How do I upgrade to Ruby 2.2 on my Ubuntu system?

Why not use ruby 2.3 which is available in the repositories for 16.04 and 17.10 with

sudo apt update

After the update is finished run:

sudo apt-get install ruby2.3 ruby2.3-dev

Or try ruby 2.4 or 2.5

You can get those via the brightbox PPA

  1. Add the repository and update

    sudo apt-add-repository ppa:brightbox/ruby-ng && sudo apt-get update
    
  2. install

    sudo apt-get install ruby2.4
    

    or for 18.04

    sudo apt-get install ruby2.5 ruby2.5-dev
    

Information on the status of packages in the aforementioned PPA can be found on the “Brightbox” team launchpad page.

Alternatively you could try reverse hacking the error alternative path /usr/bin/ruby2.2 doesn't exist by creating it with sudo mkdir /usr/bin/ruby2.2 and trying again.