rbenv helps manage your ruby environment. Checkout devhints.io/rbenvfor quick web cheat sheet.

official install method

Official installer method:
curl -fsSL https://raw.githubusercontent.com/rbenv/rbenv-installer/main/bin/rbenv-installer | bash

my method

I love just having rbenv available even if I'm not doing any ruby stuff on a system so I have the following rbenv.sh file in my .bash.d folder to ensure I've got the needed hints to get it setup if it isn't available.

which rbenv > /dev/null 2>&1
if [ $? -ne 0 ]; then
  # missing rbenv - check if it just need to be loaded
  if [ -d $HOME/.rbenv/bin ]; then
    export PATH=$HOME/.rbenv/bin:$PATH
    eval "$(rbenv init -)"
  else
    # nope, not available to load, perhaps we don't want it
    if [ -f .rbenv ]; then
      return 1
    else
      # we apparently want it
      echo "missing rbenv.  Do following line if you want to install it"
      echo "curl -fsSL https://raw.githubusercontent.com/rbenv/rbenv-installer/main/bin/rbenv-installer | bash"
      echo "to suppress this message touch $HOME/.rbenv"
      return 1
    fi
  fi
fi

if [ -f ~/.ruby-version ]; then
  rbenv global `cat ~/.ruby-version`
  if [ $? -ne 0 ]; then
    echo "rbenv failed to set ~/.ruby-version: `cat ~/.ruby-version`"
    echo "fix this: rbenv install `cat ~/ruby-version`"
  fi
fi

which rbenv > /dev/null 2>&1
if [ $? -ne 0 ]; then
  # odd, still missing rbenv in environment
  echo "odd, still missing rbenv in the environment"
else
  which bundler > /dev/null 2>&1
  if [ $? -eq 1 ]; then
    echo "missing bundler: gem install bundler"
  fi
fi

Digital Ocean Ubuntu 22.04 Instructions summary of all the steps

sudo apt update
sudo apt install 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/HEAD/bin/rbenv-installer | bash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
type rbenv
rbenv install -l
rbenv install (latest version i.e 3.2.2)