How to Install and Use Ruby and RVM on an Ubuntu Cloud Server?

04-02-2024 02:49:09

Ruby is a popular programming language, and RVM (Ruby Version Manager) is a tool for managing multiple Ruby environments, facilitating easy switching between versions. This guide is based on an Ubuntu operating system cloud server and provides instructions for installing and using Ruby and RVM.

First, install GPG and import the RVM key. Please confirm the key on the official RVM website: https://rvm.io/rvm/security

$ sudo apt install gnupg
$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

Next, download and install RVM.

$ cd /tmp
$ sudo apt-get update && apt-get install curl && curl -sSL https://get.rvm.io | bash -s stable

Check the RVM version.

$ rvm -v
rvm 1.29.9 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

List the current Ruby versions.

$ rvm list known

Install a specified version of Ruby.

$ rvm install ruby-2.7.0
$ rvm --default use ruby-2.7.0

Remove a specified version of Ruby.

$ rvm remove ruby-2.7.0

Uninstall RVM.

$ sudo rvm implode
$ sudo rm -rf ~/.rvm
$ sudo rm -rf /etc/rvmrc
$ sudo rm -rf ~/.rvmrc
$ sudo groupdel rvm

Then, remove RVM-related code from the following files and reboot the operating system: .bashrc, .bash_profile, .profile, .zshrc.