Chef and Ruby

How To Install Chef and Ruby with RVM on Ubuntu 24.04

Welcome back to the Greenhost.cloud blog! Today, we’re going to guide you through the process of installing Chef and Ruby using RVM (Ruby Version Manager) on Ubuntu 24.04. Chef is a powerful automation platform that transforms infrastructure into code, and Ruby is the programming language that powers Chef. Let’s get started!

Prerequisites

Before we dive into the installation process, make sure you have the following:

  • A server or machine running Ubuntu 24.04.
  • A user account with sudo privileges.
  • Internet access to download packages and dependencies.

Step 1: Update Your System

First, we need to ensure that all your existing packages are up to date. Open your terminal and run the following command:

sudo apt update && sudo apt upgrade -y

This command will update the package list and upgrade any outdated packages.

Step 2: Install Required Dependencies

Chef and RVM require certain dependencies to function correctly. Install them using the following command:

sudo apt install -y curl gpg build-essential libssl-dev libreadline-dev zlib1g-dev
  • curl: Used to download files from the Internet.
  • gpg: Used for verifying the authenticity of the downloaded files.
  • build-essential: Contains packages for compiling software.
  • libssl-dev, libreadline-dev, zlib1g-dev: Required libraries for Ruby development.

Step 3: Install RVM (Ruby Version Manager)

RVM makes it easy to install and manage multiple Ruby versions. To install RVM, follow these steps:

  1. Download and Install RVM:
   \curl -sSL https://get.rvm.io | bash -s stable

This command will download and install the latest stable version of RVM.

  1. Load RVM: After installation, you need to load RVM into your current shell session. You can do this by running:
   source ~/.rvm/scripts/rvm

To ensure that RVM loads automatically in future sessions, add the above line to your ~/.bashrc file:

   echo 'source ~/.rvm/scripts/rvm' >> ~/.bashrc
   source ~/.bashrc
  1. Verify RVM Installation: You can verify that RVM was installed correctly by checking the version:
   rvm --version

Step 4: Install Ruby

Now that RVM is installed, let’s install Ruby. You can install the latest stable version of Ruby by running:

rvm install ruby

To set this version as the default, use:

rvm use ruby --default

You can verify the Ruby installation by checking its version:

ruby -v

Step 5: Install Chef

With Ruby installed, we can now install Chef. The easiest way to install Chef is by using the following command:

gem install chef

This command will download and install the latest version of Chef.

Step 6: Verify Chef Installation

After the installation, you can verify that Chef is installed correctly by checking its version:

chef -v

You should see the version of Chef you just installed.

Step 7: Clean Up

Once you’ve confirmed that both Ruby and Chef are installed, you may want to clean up any unused packages to free up space:

sudo apt autoremove -y

Conclusion

Congratulations! You have successfully installed Chef and Ruby using RVM on your Ubuntu 24.04 system. With Chef, you can now automate your infrastructure management and deployment processes.