To install mysql2 or nokogiri gem without any errors, you’ll need to install libmysqlclient-dev and build-essential.
sudo apt update
sudo apt install ruby-dev libmysqlclient-dev build-essential -y
sudo gem install mysql2
sudo gem install nokogiri
I’ll be testing if the installation was successful by getting the price of Bitcoin from coingecko site.
Create a file “get_btc_price.rb” and paste the content below into it.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
page = Nokogiri::HTML(URI.open("https://www.coingecko.com/en"))
puts page.css('span[data-coin-symbol="btc"]').text
Then execute it by running.
ruby get_btc_price.rb