Ruby on Rails is a popular web application framework designed to help you develop successful projects while writing less code.
RVM, or Ruby Version Manager, is a command line tool that lets you manage and work with multiple Ruby development environments and allows you to switch between them.
sudoprivileges. Learn how to set this up by following our initial server setup guide.
When you are ready to continue, log in as your
First, you’ll need to install or update GPG (GNU Privacy Guard) to the most recent version in order to contact a public key server and request a key associated with the given ID:
- sudo apt update
- sudo apt install gnupg2
Next, you’ll request the RVM project’s public key to verify the legitimacy of your download:
- gpg2 --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
You’ll use the
curl command to download the RVM installation script from the project’s website:
- \curl -sSL https://get.rvm.io -o rvm.sh
The backslash that leads the command ensures that we are using the regular
curl command and not any altered, aliased version. The
-s flag indicates that the utility should operate in silent mode along with the
-S flag to still allow
curl to output errors if it fails. The
-L flag tells the utility to follow redirects, and finally the
-o flag indicates to write output to a file instead of standard output.
Once it is downloaded, if you would like to audit the contents of the script before applying it, run:
- nano rvm.sh
To close out of
nano, hit CTRL-X.
Now, you can pipe it to
bash to install the latest stable Rails version which will also pull in the associated latest stable release of Ruby.
- cat rvm.sh | bash -s stable --rails
When the installation is complete, source the RVM scripts from the directory they were installed:
- source ~/.rvm/scripts/rvm
You should now have a full Ruby on Rails environment configured.
If you need to install a specific version of Ruby for your application, rather than just the most recent one, you can do so with RVM. First, check to see which versions of Ruby are available by listing them:
- rvm list known
Then, install the specific version of Ruby that you need through RVM, replacing the highlighted version number with your version of choice, such as
ruby-3.0.0 or just
- rvm install 3.0.0
After the installation, you can list the available Ruby versions you have installed by typing:
- rvm list
You can switch between the Ruby versions by typing:
- rvm use 3.0.0
Since Rails is a gem, which is a standardized format that contains Ruby programs, you can also install various versions of Rails by using the
gem command. Let’s first list the valid versions of Rails by doing a search:
- gem search '^rails$' --all
Next, you can install your required version of Rails. Replace the highlighted version number with your version of choice, such as
- gem install rails -v 7.0.2
You can use various Rails versions with each Ruby by creating gemsets and then installing Rails within those using the normal
To create a gemset you will use:
- rvm gemset create gemset_name
To specify a Ruby version to use when creating a gemset, use:
- rvm 3.0.0@gemset_name --create
The gemsets allow us to have self-contained environments for gems as well as have multiple environments for each version of Ruby that you install.
Out of the box, Rails does not require Node.js since
importmaps is now used by default. In practice, you may run into apps that still require it.
First, verify the Node.js script by outputting it to a file, then read it with
- \curl -sSL https://deb.nodesource.com/setup_17.x -o nodejs.sh
- nano nodejs.sh
Once you are satisfied with the Node.js script, you can install the NodeSource Node.js v17.x repo:
- cat nodejs.sh | sudo -E bash -
-E flag used here will preserve the user’s existing environment variables.
Now you can update apt and use it to install Node.js:
- sudo apt update
- sudo apt install nodejs
At this point, you can begin testing your Ruby on Rails installation and start to develop web applications.
If you no longer wish to use RVM, you can uninstall it by first removing the script calls in your
.bashrc file and then removing the RVM files.
First, remove the script calls with a text editor like nano:
- nano ~/.bashrc
Scroll down to where you see the RVM lines of your file:
... # Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin"
Delete the lines, then save and close the file.
Finally, remove RVM with the following command:
- rm -rf ~/.rvm
You have covered the basics of how to install RVM and Ruby on Rails here so that you can use multiple Ruby environments.
For your next steps, you can learn more about working with RVM and how to use RVM to manage your Ruby installations.
If you’re new to Ruby, you can learn about programming in Ruby by following our How To Code in Ruby tutorial series.
For more scalability, centralization, and control in your Ruby on Rails application, you may want to use it with PostgreSQL rather than its default sqlite3 database.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.Sign up