How to use version managers with RoR

Mateo mojica
4 min readNov 9, 2023
Photo by Brad on Unsplash

Version managers are an important part of any development environment, in this article, I’m going to show you the most used version managers for Ruby on Rails projects and some of their functionality.

Version managers are tools used in software development that manage and control the versions of the programming languages, libraries, and frameworks installed on a developer’s system. They help ensure that the correct versions of these components are used for a particular project. Two of the most common version managers for Ruby are RVM and Rbenv.

Version managers are essential for ensuring that your Ruby on Rails application can run with the correct Ruby version and associated gems that the project depends on without conflicts.

Additionally, version managers often work with a gemfile, where all the project’s dependencies are specified to ensure consistency when working within a team. This approach helps the development team to be fast, and consistent and creates a reliable and reproducible development environment for every developer.

Photo by Jerry Yu on Unsplash

Now let’s explore two of the most popular version managers used for Ruby on Rails, RVM, and Rbenv. Rbenv is a lightweight and popular version manager for Ruby. It allows developers to manage multiple Ruby version installations on their computers and easily switch between them. It is known for its simplicity and flexibility, making it convenient for managing Ruby versions in a development environment. With Rbenv, developers can ensure that each project they work on uses the appropriate version of Ruby and associated gems, helping to avoid version conflicts and ensuring project compatibility.

RVM or Ruby Version Manager is another version manager for Ruby and has the same functionality as Rbenv but also expands on it giving the option of creating isolated gemsets (sets of Ruby versions and gems) for specific projects, and manage dependencies efficiently, this helps the team to prevent conflicts and ensures that each Ruby project has the necessary version and gems to run correctly.

Both RVM and Rbenv are tools used to manage Ruby versions, but they have some key differences:

  • Complexity: RVM has more features than Rbenv and provides a wide range of capabilities, including gemsets, environment management, and more, this features make it more complex to set up and run.
  • Isolation: RVM uses gemsets to isolate environments between projects, allowing to manage gems at the project level. Rbenv does not provide that functionality by default.
  • Compatibility: Rbenv is designed to be lightweight and compatible with different shells, focusing on the core task of managing Ruby versions, this can make it more suitable for minimalistic or specific use cases.
  • Plugin ecosystem: Both RVM and Rbenv allow plugins to extend functionality and customize the setup.
  • Community: Although RVM has been around for a longer time and has a larger user base, but the development activity has slowed down in recent years. On the other hand, Rbenv is actively maintained and has a strong community of users and contributors, making the support of it very easy.
Photo by Joan Gamell on Unsplash

To install Rbenv in your computer there are a variety of methods to do it depending on your operating system, the official guide on how to install and use it is in the RBENV GitHub repo, you should check it out to follow the steps specific to your needs.

Here are some useful commands for Rbenv:

# list latest stable versions:
rbenv install -l

# list all local versions:
rbenv install -L

# install a Ruby version:
rbenv install 3.1.2

rbenv global 3.1.2 # set the default Ruby version for this machine
# or:
rbenv local 3.1.2 # set the Ruby version for this directory

# List all the versions for Rbenv
rbenv versions

# Reload after installations
rbenv rehash

Installing RVM is a little bit more complicated than installing Rbenv, the official documentation lays out the steps to install it and you can look for the specific guide for your operating system.

Here are some useful commands for RVM:

# Install ruby version 2.7.4
rvm install 2.7.4

# List all the installed ruby versions
rvm list

# Use a ruby version and set it as default for the system
rvm use ruby_version --default

# Create a gemset
rvm gemset create gemset_name

# Use a gemset for the project
rvm use ruby_version@gemset_name

# List all gemsets
rvm gemset list

# Delete a gemset
rvm gemset delete ruby_version@gemset_name

# Update RVM
rvm get stable

# Uninstall a ruby version
rvm remove ruby_version

Thank you for reading this article, I hope it helped you to understand how version managers work and what they are used for. If you liked it give it a clap and consider reading my other articles on different topics also consider following me to get notified when I publish something new.

References

--

--