Skip to content

Instantly share code, notes, and snippets.

@jcave
Last active October 29, 2019 18:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcave/7a368bc9b1f44a91f331 to your computer and use it in GitHub Desktop.
Save jcave/7a368bc9b1f44a91f331 to your computer and use it in GitHub Desktop.
Upgrading Ruby using RVM on Digital Ocean's Ruby on Rails on Ubuntu 14.04 (Nginx + Unicorn) Image

Upgrading Ruby using RVM on Digital Ocean's Ruby on Rails on Ubuntu 14.04 (Nginx + Unicorn) Image

For those out there more advanced, this is probably not worth reading. However, if you’re fairly new to system admin on a Digital Ocean Ubuntu/Nginx/Unicorn/MySQL/Ruby on Rails setup, it may help you out. Recently, I needed to upgrade my ruby version from 2.0.0-p353 to version 2.2.0 on my Digital Ocean droplet. I felt like this would be fairly easy to do since RVM comes installed with the ‘Ruby on Rails on 14.04 (Unicorn + Nginx)’ image that Digital Ocean provides under the ‘Applications’ tab when creating a Droplet.

While it is true that installing a new version of ruby using RVM on your system is fairly easy, there’s a few locations that you MUST change in order to use the new ruby version. This is where if you are unfamiliar or new to this, you could spend a decent amount of time digging for these. Hopefully this will save you the time and make your upgrade fairly smooth.

Let’s get started!

Step 1: Take a Snapshot

Before you upgrade, you should create a snapshot of your system just in case something bad happens. By doing this you can also spin up new cloned droplet to try it out before you do it live as many things can potentially break when changing ruby versions.

Step 2: Upgrade your RVM

Jump into your system via ssh. Once your in, it’s probably good to make sure your RVM is up to date. You can upgrade via simple command: rvm get head. When the upgrade is complete, you may get an upgrade note of ‘It looks like some old stuff is laying around RVM, you can cleanup with: rvm cleanup all’. Go ahead and run rvm cleanup all to remove any junk laying around.

Step 3: Install the Latest Ruby (or whatever version you want)

For me, I wanted to install ruby 2.2.0, but you can also just install the latest if you want. Syntax as follows:

rvm install 2.0.0 --disable-binaries or rvm install ruby --latest --disable-binaries

Additionally, if you’d like to know what ruby versions are available you can type rvm list known.

Once installed, make sure you make it your new default ruby.

rvm use 2.2.0 --default

At this point you can either keep or remove your old ruby version - rvm remove 2.0.0-p353. If you’d like to see the versions installed, use rvm list.

Step 4: Change Your Unicorn Configs

The initial image that Digital Ocean provides you has a couple unicorn config files that you’ll need to update to point to the new version of ruby you just installed.

Verify your new ruby and gem are the default by typing: which ruby and which gem. These should echo back a path that contains the new version of ruby. For example I installed ruby 2.2.0 and my path is now ‘/usr/local/rvm/rubies/ruby-2.2.0/bin/ruby’. Keep track of this version numbers as this is what you’ll need in order to replace the older version.

Edit the ‘/etc/default/unicorn’ and ‘/etc/init.d/unicorn’ files and replace the old ruby version with the new one everywhere it’s found. I use ‘nano’ as the editor.

nano /etc/default/unicorn (change ‘ruby-2.0.0-p353’ to ‘ruby-2.2.0’) There should be a PATH variable to change.

nano /etc/init.d/unicorn (change ‘ruby-2.0.0-p353’ to ‘ruby-2.2.0’) There should be GEM_HOME, GEM_PATH, and DAEMON variables to change. If one contains an ‘@global’ leave that piece, just change the version number that precedes it.

Step 5: Install unicorn, rails, and bundler gems for the new Ruby version

Add these gems for your new version of ruby. This will take a while. gem install bundler rails unicorn

Step 6: Veryify your Ruby in your Gemfile and bundle your application

Browse to your application cd /home/rails. Once there, make sure you have the new version of ruby specified in your Gemfile. When you do, run bundle. It may choke and ask you to run bundle update which is fine.

Step 7: Restart Unicorn

You should now be able to restart unicorn using the new ruby version.

service unicorn restart

Additionally, after you restart, also look in the unicorn log file to see if any gem errors are happening. To do this, use tail -f /home/unicorn/log/unicorn.log. If you have any errors, scroll through them and see if you can fix them, then try to restart the service again.

In the past I got some errors when running an older version of rails (4.1.2) with the newest version of ruby (2.2.0). I solved it by simply upgrading to rails 4.2.0. That’s not always an option, so you might have to play around with your gems a bit.

Step 8: No do it in production!

Good luck! Hope this helps for those folks that are fairly new at this.

@pisaq
Copy link

pisaq commented Feb 21, 2015

TYPO

rvm install 2.0.0 --disable-binaries

should be 2.2.0

@kazpsp
Copy link

kazpsp commented Mar 2, 2015

hey, i get an error when trying to install 2.2.0:

rror running '__rvm_make -j1',
showing last 15 lines of /usr/local/rvm/log/1425339775_ruby-2.2.0/make.log
generating transdb.h
transdb.h updated
making trans
make[1]: Entering directory /usr/local/rvm/src/ruby-2.2.0' compiling ./enc/trans/transdb.c linking transcoder transdb.so compiling ./enc/trans/big5.c gcc: internal compiler error: Killed (program cc1) Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions. make[1]: *** [enc/trans/big5.o] Error 4 make[1]: Leaving directory/usr/local/rvm/src/ruby-2.2.0'
make: *** [trans] Error 2
++ return 2

any ideas?

@timokleemann
Copy link

Awesome tutorial, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment