
How to Install Ruby on Rails with RVM on Ubuntu 24
Installing Ruby on Rails with RVM (Ruby Version Manager) on Ubuntu 24 is the go-to approach for developers who need flexible Ruby version management and streamlined Rails development environments. This combination gives you fine-grained control over Ruby versions per project, eliminates system-wide Ruby conflicts, and provides a rock-solid foundation for Rails applications. We’ll walk through the complete installation process, tackle common roadblocks, and show you how to optimize your setup for real-world development scenarios.
Why RVM Makes Sense for Rails Development
RVM stands out from other Ruby version managers because it handles gemsets alongside Ruby versions, creating isolated environments for different projects. Unlike rbenv or asdf, RVM gives you complete sandboxing without additional plugins or configuration gymnastics.
Feature | RVM | rbenv | asdf |
---|---|---|---|
Gemset Management | Built-in | Plugin required | Not available |
Shell Integration | Full shell override | Shim-based | Shim-based |
Installation Complexity | Medium | Low | Medium |
Multi-language Support | Ruby only | Ruby only | Multiple languages |
Prerequisites and System Preparation
Before diving into RVM installation, Ubuntu 24 needs several development packages. These dependencies ensure smooth Ruby compilation and Rails functionality.
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl gpg build-essential libssl-dev libreadline-dev zlib1g-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn postgresql postgresql-contrib libpq-dev imagemagick libvips42
The nodejs and yarn packages handle JavaScript compilation for Rails asset pipeline, while postgresql and imagemagick support common Rails application requirements.
Installing RVM and Ruby
RVM installation involves importing GPG keys and running the installation script. This approach ensures cryptographic verification of the RVM codebase.
# Import RVM GPG keys
gpg --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
# Download and install RVM
curl -sSL https://get.rvm.io | bash -s stable
After installation, reload your shell configuration to activate RVM:
source ~/.rvm/scripts/rvm
Verify RVM installation and check available Ruby versions:
rvm --version
rvm list known
Install the latest stable Ruby version (3.2.0 as of this writing):
rvm install 3.2.0
rvm use 3.2.0 --default
The compilation process takes 5-15 minutes depending on your server specifications. For faster installations on VPS environments, consider using pre-compiled Ruby binaries:
rvm install 3.2.0 --binary
Installing Rails and Creating Your First Application
With Ruby installed, install Rails using the gem command. Skip documentation generation for faster installation:
gem install rails --no-document
Create a new Rails application to test your setup:
rails new testapp --database=postgresql
cd testapp
bundle install
The bundle install command installs all gems specified in the Gemfile. This process downloads and compiles native extensions, which benefits from multiple CPU cores available on dedicated server configurations.
Managing Multiple Ruby Versions and Gemsets
RVM’s killer feature is managing multiple Ruby versions with isolated gemsets. Create project-specific environments:
# Create and use a new gemset
rvm gemset create myproject
rvm use 3.2.0@myproject
# Install project-specific gems
gem install rails -v 7.0.4
gem install sidekiq redis
Use .rvmrc files for automatic environment switching:
# In your project directory
echo "rvm use 3.2.0@myproject" > .rvmrc
cd .. && cd myproject # Triggers automatic gemset switching
Performance Optimization and Best Practices
Several configurations improve Rails development performance on Ubuntu 24:
- Enable gemset caching to reduce bundle install times
- Configure Ruby garbage collection for development workloads
- Use precompiled gems when available
- Set up shared gemsets for common development gems
Configure Ruby memory settings for better performance:
# Add to ~/.bashrc or ~/.zshrc
export RUBY_GC_HEAP_INIT_SLOTS=1000000
export RUBY_GC_HEAP_FREE_SLOTS=500000
export RUBY_GC_HEAP_GROWTH_FACTOR=1.1
Create a shared gemset for development tools:
rvm gemset create global
rvm @global do gem install bundler rubocop pry byebug
Common Issues and Troubleshooting
Several issues commonly surface during RVM and Rails installation on Ubuntu 24:
RVM Command Not Found: This happens when shell configuration doesn’t load RVM scripts. Add this line to your ~/.bashrc:
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Ruby Compilation Failures: Missing development headers cause compilation errors. Install the complete build environment:
sudo apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
Permission Errors: Never use sudo with RVM commands. RVM installs in user space intentionally. If you encounter permission issues:
rvm fix-permissions
rvm repair all
Gemset Loading Issues: Gemsets sometimes fail to load automatically. Force reload with:
rvm reload
rvm gemset list
Real-World Development Scenarios
Here are practical examples of RVM usage in development teams:
Legacy Application Maintenance: Maintain multiple Rails versions simultaneously:
# Legacy app on Rails 5.2
rvm install 2.7.6
rvm use 2.7.6@legacy_app
gem install rails -v 5.2.8
# Modern app on Rails 7
rvm use 3.2.0@modern_app
gem install rails -v 7.0.4
Client Project Isolation: Separate client environments completely:
rvm gemset create client_a
rvm gemset create client_b
rvm use 3.2.0@client_a --create
# Install client A specific gems and versions
Testing Different Ruby Versions: Test application compatibility across Ruby versions:
#!/bin/bash
for version in 3.0.5 3.1.3 3.2.0; do
rvm use $version
bundle exec rspec
echo "Tests completed for Ruby $version"
done
Integration with Development Tools
RVM integrates seamlessly with popular development tools and editors. Configure your IDE to recognize RVM Ruby paths:
# Find current Ruby path for IDE configuration
which ruby
# Returns: /home/username/.rvm/rubies/ruby-3.2.0/bin/ruby
For VS Code users, add this configuration to settings.json:
{
"ruby.interpreter.commandPath": "/home/username/.rvm/rubies/ruby-3.2.0/bin/ruby",
"ruby.format": "rubocop"
}
Automate environment setup with shell scripts:
#!/bin/bash
# setup_rails_project.sh
rvm use 3.2.0@$1 --create
gem install bundler rails
rails new $1 --database=postgresql
cd $1
echo "rvm use 3.2.0@$1" > .rvmrc
Security Considerations and Updates
Keep RVM and Ruby versions updated for security patches:
# Update RVM itself
rvm get stable
# List installed Ruby versions
rvm list
# Update to latest patch version
rvm install 3.2.1
rvm use 3.2.1 --default
Monitor Ruby security advisories through the official Ruby security announcements at ruby-lang.org/en/security/.
Remove old Ruby versions to save disk space:
rvm remove 3.1.0
rvm cleanup all
This setup provides a robust, flexible Rails development environment on Ubuntu 24. RVM’s gemset isolation prevents dependency conflicts while maintaining easy version switching for multiple projects. Regular maintenance and updates ensure your development environment stays secure and performant for long-term Rails development work.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.