All posts in General

How to fix Envoyer deployment failing with old ruby version

NOTE: I’m getting more and more used to documenting strange fixes to some random sysop issues I run into. I seem to run into them more than once since I am usually managing more than one server, but my memory sucks, so I write my own documentation to find the solution again, especially if it’s a complex one that I bang my head against the wall with for hours or days. Since I do this for myself, I figure I’ll publish them for you as well. I hope it’s helpful.

ANOTHER NOTE: This particular issue was experienced on a Digital Ocean server running Ubuntu 14.04. (Side note, to figure out what version/flavor of Ubuntu you are running, simply run lsb_release -a and voila.)

Ok, on to the issue and fix.

Problem: When deploying using Envoyer I received an error saying the ruby version was 1.9.3 and needed to be 2.3.0 or higher (preferably 2.3.1 it seems).

Solution: Upgrade the ruby version used while inside sudo -s.

How to Fix:

First, be sure you’re in the right place after ssh’ing into the server.  Envoyer does a sudo -s in certain instances, so let’s make sure we’re updating the version that’s used in that context.

sudo -s

Now, if rbenv is not up to date (which you can tell if you run ruby-build --definitions and don’t see the version of ruby you want to install in the list) you can refer to https://gist.github.com/njh/1f28803af2ecf420cdaf, and/or put this in a script or just run it line by line as needed…

# Download rbenv
if [ ! -d ~/.rbenv ]; then
  git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
fi

cd ~/.rbenv
git reset --hard
git pull origin master

# Download ruby-build
if [ ! -d ~/.rbenv/plugins/ruby-build ]; then
  git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
fi

cd ~/.rbenv/plugins/ruby-build
git reset --hard
git pull origin master

# Setup rbenv
cd ~
export HOME=`pwd`
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

rbenv --version
rbenv versions
rbenv install --list

That will update rbenv, however, it won’t update ruby for you. So, the next thing to do is install the appropriate version locally and globally, and then rehash which forces the system to recognize the new version (in this virtual terminal session) …

rbenv install 2.3.1
rbenv global 2.3.1
gem install bundler
rbenv rehash


Once that’s done, we want to make sure this version persists without having to rehash every time sudo -s is run. So let’s use some of the bits of the above script to edit the appropriate bash script that’s loaded when the virtual terminal is loaded.  For this, we need to…

vim ~/.bashrc

NOTE: I also edited /root/.bashrc for good measure with the same lines. I’m not sure which one is the correct one for this, so I just edited both. If you know the answer, let me know in the comments and I’ll update this post as well as my docs accordingly. Thanks in advance!

vim /root/.bashrc

Inside these files, at the top, add the following lines in order…

export HOME=`pwd`
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"


Save and close the file(s) and when you’ve done both, exit the virtual terminal. Now, sudo -s back in and call …

ruby -v

… and you should now see the correct version (in this example 2.3.1). Once this is done, Envoyer should be able to deploy properly.