Ubuntu Install Nokogiri

Kevin FOO
Sep 22, 2020


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.

Sample html of coingecko

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
Successfully getting Bitcoin price from coingecko

< Back to all the stories I had written



Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.