How to Upgrade Ruby on Ubuntu 22.04 Using rbenv

How to Upgrade Ruby on Ubuntu 22.04 Using rbenv

Upgrading Ruby on Ubuntu can be smoothly handled with a version manager like rbenv. This approach is not only efficient but it also allows for easy switching between different Ruby versions. Below is a step-by-step guide on installing rbenv and using it to upgrade Ruby to your desired version.

Installing rbenv and Ruby-build

Follow these steps to set up rbenv and ruby-build on your system:

  1. Install rbenv and ruby-build: This step involves pulling rbenv and its plugin ruby-build from GitHub, which helps in managing multiple Ruby versions.
    sudo apt update
    sudo apt install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
    curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-installer | bash
    
  2. Configure rbenv integration: Add rbenv to your shell to enable shims and autocompletion by appending the following lines to your shell configuration file.
    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(rbenv init -)"' >> ~/.bashrc
    exec $SHELL
    

    If you use zsh, replace .bashrc with .zshrc.

  3. Check the rbenv installation: Ensure that rbenv is integrated correctly into your shell.
    type rbenv

    This command should output "rbenv is a function".

Installing Ruby 3.2.3 or 3.3

Once rbenv is set up, proceed to install a new Ruby version:

  1. List all available versions of Ruby:
    rbenv install -l

    Look for the latest stable versions or any specific version you wish to install.

  2. Install Ruby:

    If Ruby 3.2.3 or another version like 3.3 is available, install it using:

    rbenv install 3.2.3  # Replace 3.2.3 with the desired version
    rbenv global 3.2.3   # Set the installed version as the default
  3. Verify the installed Ruby version:
    ruby -v

    This command will display the Ruby version you have set as default, confirming the successful installation.

By following these steps, you can manage different Ruby versions on your Ubuntu system effectively, allowing you to develop and test Ruby applications with ease.

Recent Comments

There are currently no comments. Be the first to make a comment.

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.