Install rails on ubuntu

  1. Install Ruby and SQLite3
  2. Install Rails with gem
    1
    sudo gem install rails
    got below error:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri
    /usr/bin/ruby2.5 -r ./siteconf20200314-38-xxyy88.rb extconf.rb
    checking if the C compiler accepts ... yes
    Building nokogiri using packaged libraries.
    Using mini_portile version 2.4.0
    checking for gzdopen() in -lz... no
    zlib is missing; necessary for building libxml2
    *** extconf.rb failed ***
    After try install nokogiri
    1
    sudo gem install nokogiri
    Error:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ERROR:  Error installing nokogiri:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/nokogiri-1.10.9/ext/nokogiri
    /usr/bin/ruby2.5 -r ./siteconf20200314-78-1wo5kzo.rb extconf.rb
    checking if the C compiler accepts ... yes
    Building nokogiri using packaged libraries.
    Using mini_portile version 2.4.0
    checking for gzdopen() in -lz... no
    zlib is missing; necessary for building libxml2
    checked log and found the cause, install libz-dev and then install nokogiri
    1
    2
    3
    vim /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.9/mkmf.log
    sudo apt-get install libz-dev
    sudo gem install nokogiri
  3. try install rails again
    1
    sudo gem install rails
    Check result with rails -v.
    It’s done.

Reference from:

  1. Getting Started with Rails

  2. How to fix fatal error: zlib.h: no such file or directory?