More Freedom with GNU Stow
In honour of our friends down South celebrating their independence, let's look at installing a local version of ruby onto a POSIX machine without requiring wrappers like rvm
or rbenv
. We want to be free to install things where we want, when we want, and how we want. Now that's true freedom.
Install GNU Stow
Okay, you are going to need to install stow system wide for this step. This requires administrative permissions. I promise it's the only thing.
$ sudo apt-get update
$ sudo apt-get install stow -y
Install build tools
Okay, I lied. You'll also need to install build-essential
on your machine because we will be compiling and installing packages from source. Some machines don't have the full build suite of compilers and other tools installed.
$ sudo apt-get install build-essential -y
Setup your home directory
$ mkdir ~/.local
It is a dot-directory so that it remains hidden from everyday view. You don't want to see it cluttering up your ls
results. Now we setup a structure similar to /usr/local
for ease (I believe this is optional, but YMMV).
$ cd ~/.local
$ mkdir bin etc games include lib man sbin share src
Update your PATH
Create a .bash_profile
to point to the binaries in the .local
directory.
$ echo "export PATH=$HOME/.local/bin:$PATH" >> ~/.bash_profile
$ source ~/.bash_profile
Create a Stow directory
Now create a directory in your .local
directory to hold everything that stow will manage.
$ mkdir ~/.local/stow
Install Ruby 2.1.2
First download the source tarball.
$ wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
Then unpack the tarball.
$ tar xfz ruby-2.1.2.tar.gz
Now configure, compile and install it.
$ cd ruby-2.1.2
$ ./configure --prefix=/home/typicalrunt/.local/stow/ruby-2.1.2
$ make
$ make install
Activate the package
$ cd .local/stow
$ stow ruby-2.1.2
Check the installation
$ which ruby
/home/typicalrunt/.local/bin/ruby
$ ruby -v
2.1.2p95
Install some gems
You'll notice that you do not have to use sudo
privileges in order to install gems. This is because all gems are stored within the .local/stow/ruby-2.1.2
directory.
$ gem install bundler
Check the Installation
$ which bundle
$
Uh-oh. Something's wrong. Bundler doesn't seem to be available as a command. The issue is that Stow hasn't symlinked it into the .local/bin
directory. All we do is tell stow to restore the symlink.
$ cd .local/stow
$ stow --restore ruby-2.1.2
And now all the new gem binaries are visible in the .local/bin
directory.
$ which bundle
/home/typicalrunt/.local/bin/bundle
Upgrading or Downgrading Ruby
Now let's have some fun. Let's try installing Ruby 2.0.0 and seeing how Stow handles it. For our use case, it should be fairly easy to switch between ruby versions for the local user.
$ wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz
$ tar xfz ruby-2.0.0-p481.tar.gz
$ cd ruby-2.0.0-p481
$ ./configure --prefix=/home/typicalrunt/.local/stow/ruby-2.0.0-p481
$ make
$ make install
Ruby 2.0.0 is now setup and we need to deactivate Ruby 2.1.2 and activate Ruby 2.0.0.
$ cd ~/.local/stow
$ stow -D ruby-2.1.2
$ stow ruby-2.0.0-p481
Now we check the install
$ ruby -v
2.0.0-p481
Yay! But what about the gems? They are tied to the ruby version that was activated by Stow, so activating another version of Ruby means that you will need to reinstall the gems for this version of Ruby.