Updating a Ruby Version on a Remote Server
Upgrading the Ruby version on our self-built servers (e.g., AWS, Rackspace, Tgen, etc.) is a crucial task that requires careful planning and execution. The Ruby version needs to be updated before deploying any codebase that depends on the newer Ruby version; otherwise, the deployment will fail due to unsatisfied dependencies.
This page serves as a guide for engineers to properly update Ruby versions on remote servers. Always test these changes in a staging environment before applying them to production.
High-Level Instructions
Section titled “High-Level Instructions”The steps to upgrade Ruby versions can be divided into these high-level tasks:
- SSH into the staging server(s) for initial testing.
- Update the
ruby-builddatabase. - Install the new Ruby version using
rbenv. - Update the local version of Ruby using
rbenv. - Install the desired version of Bundler.
- Update the global Ruby version with
rbenv.
1. SSH into the Staging Server(s)
Section titled “1. SSH into the Staging Server(s)”Always start by testing out the upgrade on a staging server. SSH into the desired server:
ssh [user]@[staging_server_ip]Replace [user] and [staging_server_ip] with appropriate values.
2. Update the Local ruby-build Database
Section titled “2. Update the Local ruby-build Database”Navigate to the directory where ruby-build is installed and update its database:
cd /home/deploy/.rbenv/plugins/ruby-build && git pull && cd -This ensures that rbenv will have access to the latest Ruby versions.
3. Install the New Ruby Version
Section titled “3. Install the New Ruby Version”Install the new Ruby version using rbenv. Replace 2.4.1 with the version you wish to install:
rbenv install 2.4.14. Set the Local rbenv Version
Section titled “4. Set the Local rbenv Version”Update the local rbenv version to the newly installed version:
rbenv local 2.4.1This sets the version of Ruby that the local user will use.
5. Install the Desired Bundler Version
Section titled “5. Install the Desired Bundler Version”Install the Bundler version that you want to be available on the server. Replace 1.17.3 with the desired version:
gem install bundler --version 1.17.36. Update the Global Ruby Version
Section titled “6. Update the Global Ruby Version”Note: Do this step only when you are ready to deploy the changes to the server.
Set the global Ruby version to the newly installed version:
rbenv global 2.4.1Voila!
Section titled “Voila!”You have successfully updated the Ruby version on the remote server. Before moving to production, validate that all the applications and services are running as expected in the staging environment.
Best Practices
Section titled “Best Practices”- Backups: Ensure you have proper backups before initiating any upgrade process.
- Monitoring: Monitor the server’s performance after the upgrade for any unusual behavior.
- Documentation: Keep a log of version changes and any issues encountered for future reference.
- Team Communication: Always notify the team about the upgrade plans and execution status.