I have been trying to find a good solution to this for a long time:
Is there a sure-fire way to install ruby to a folder which is portable on that platform? I want to have a folder which I can easily copy into a distribution I am making so I can have a ruby environment "on the go". It is fine if I need to compile the source and stuff, as long as I end up with a portable ruby install.
I have found a few resources which tries to solve this, but none are satisfactory for me.
Portable Ruby on Rails environment
http://hcettech.blogspot.pt/2012/05/windows-portable-rails-development.html
For me this is a major pain-point of Ruby. If it is not possible to get a Ruby script to work without having the clients install Ruby first, then ruby is essentially no good in my case. I truly hope I/we can figure this out so it is possible to have Ruby be lots more useful than what it already is.
Note: I know things like Releasy exists, but it's still not a simple ruby executable.
My goal is to be able to make a folder with a .bat/.sh script, which does this:
#some bat/sh
./bin/ruby ./my_script.rb
And yes, shoot me down if there is something about this problem I have not understood, as it would be a relief for me.
I got so tired of this that I decided to make my own solution to it. After a couple of days I finally got this working.
It's just what I needed, and hopefully someone else will get the benefit of it too!
It's really simple: Download the repo (which is quite big because of the binaries). Put it on a usb-drive, or wherever you want it, then do:
path/to/ruby_ship/bin/ruby_ship.sh -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
That's for linux and mac, or on windows:
path\to\ruby_ship\bin\ruby_ship.bat -v
=> ruby 2.1.2p95 (2014-05-08 revision 45877) [i386-mswin32_100]
The ruby_ship wrapper acts just as your normal ruby, so you can pass in a script, or do anything you would use the normal ruby command for.
If you don't like the version that comes bundled with Ruby Ship, then simply use the compiling-script that is in the tools directory. Download the source code of you favourite version of Ruby, say X.Y.Z, then do this:
# *nix (osx/linux/...)
path/to/ruby_ship/tools/ruby_ship_build.sh path/to/ruby-X.Y.Z.tar.gz
# windows
path\to\ruby_ship\tools\ruby_ship_build.bat path\to\ruby-X.Y.Z.tar.gz
This will build your flavour of ruby and set up the wrappers correctly. Now you Ruby version X.Y.Z is portable! Copy paste this folder where you want it and you are ready to go! Remember though, it will only compile for your current platform, so if you need other platforms, go compile it on those platforms as well.
The compiling process has a few requirements. Look at the github site.
Anyways, hope that others might find this useful! If things are not quite working for you, please make an issue and I will look into it!
To clarify my understanding of your problem, you want to be able to package Ruby alongside your script, all contained within a single directory. Something like:
.
├── bin
│ └── ruby
├── my_script.bat
├── my_script.sh
└── my_script.rb
You want this to be work on multiple platforms - you cite batch and shell scripts as possibilities, so I'm assuming both *NIX and Windows are potential targets. This would mean shipping multiple platform-specific Ruby binaries.
Also, you mention gems that don't support JRuby, so it's possible you're using gems with native extensions.
There is no tool that satisfies all of those requirements :(
If you were willing to forgo the use of native extensions, and build a package per target platform, you could:
Needless to say this will involve a fair amount of overhead, especially if you want to fully automate those steps and test them as part of CI (which I'd recommend doing as a smoke test at the end of a full CI build).
Old post, but you can also check my solution rb2exe. It turns ruby applications into single, portable, stand-alone executables.
It supports Rails and Gemfile.
Install / usage:
gem install rb2exe
echo "puts 'Hello world'" > test.rb
rb2exe test.rb
./test
I explain what it does, step-by-step, here:
http://www.learnwithdaniel.com/2016/08/ruby-to-portable-exe-app/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With