Fix RVM “run script from the internet to install”

On Wednesday I complained about the latest UN*X fad of installing software by running scripts from the internet, without any regard to how your operating system handles software installation.

Docker, that I complained about last time, at least has a script that takes into account the local software management solution (uses apt for Ubuntu, yum for Fedora, etc), but RVM – the Ruby Version Manager which is a popular tool among rubyists everywhere, just downloads a bunch of executable stuff (granted, most of it are scripts, but the difference is lost on most people) into arbitrary location on your file system. At least it doesn’t install system software, oh wait – it does.

While I can’t help with RVM’s desire to install system level software (that it actually needs because one of the things you want RVM to do for you is to compile ruby versions from source), I can try to help you figure out how to install RVM where you want it and use it how you want it.

I’m tackling two issues here:

  1. Where to install RVM – normally this is ~/.rvm, but you may want to specify that yourself
  2. Prevent the automatic loading of the RVM shell extensions into the shell and let you control that

The main reason this is interesting for me is that I need to be able to set RVM up in a local directory on a CI system without affecting other projects running on the same system account.

Other issues that we may also want to have control of in the future are:

  • Installation of additional system software to support building ruby from source
  • Select the RVM version to install, download and install it manually (the setup below lets the internet installer do that)

Setup

We start by downloading the install from the RVM website, similar to how the website instructs you to, but we aren’t going to just feed it into the shell – we’ll just save it:

curl https://get.rvm.io -o rvm-installer

Now we are going to run it without worrying too much 😉1

bash rvm-installer stable --ignore-dotfiles --path where/to/install

The --ignore-dotfiles switch is to tell RVM to keep its dirty paws off of our precious shell configuration files, and --path is used to select where we want RVM to install itself. Under that directory it will also create the folder where it will download and build all its ruby binaries – so its pretty self-contained, but you want to make sure there is enough space there: an RVM setup can quickly grow to 500 MB or more. I usually install such things to ~/.local/rvm or maybe ~/.local/share/rvm though the longer the path, the more you’d need to type when you want to use it…

After the RVM installer has done its thing, you can choose when to load it into your shell to engage in your RVM habit – whenever you start a new shell that you want to be “RVM enabled”, import the RVM shell extension from the RVM scripts directory. For example, if I installed RVM under ~/.local/rvm, I’d run:

source ~/.local/rvm/scripts/rvm

You can also use RVM with almost all the functionality by using the RVM command as a normal command (without the shell extension). If you have that behavior in mind, then I recommend symlinking the RVM executable to your local bin directory (this is ~/bin by default, but I like to move it to ~/.local/bin as it makes more sense to me. The example above assumes that you did as well):

ln -s ~/.local/rvm/bin/rvm ~/.local/bin/rvm

After you do that, you can just run rvm whenever you want to use it. Do remember that without the shell extension loaded, RVM can’t take over the commands ruby, gem and friends, so if you want to run commands on the RVM managed ruby, you need to run something like rvm <version> do gem.

  1. OK, that’s kind of hypocritical – we should read the source and understand what it is doing before unleashing it on our unsuspecting home directory, but this is the “TODO” above. Also the RVM shell code is really hard to read… []

3 Responses to “Fix RVM “run script from the internet to install””

  1. Amir:

    Sad but true, someone actually made a collection of these from around the ’net: http://curlpipesh.tumblr.com/

  2. Oded:

    Oh, the awesomeness of horribleness 🙁

  3. Fix another ‘curl|sh’ bogus installation – Heroku :: Things n' Stuff:

    […] (which I don’t remember if its mentioned in the “curlpipesh” tumbler mentioned by Amir in his response to my “Fix RVM” post), is a CLI to manage applications on the Heroku PaaS platform. As is common (and horrible) in this […]

Leave a Reply