Installing Ruby + Rails on Ubuntu 18.04 (rbenv)

Purpose

I tried to install Ruby and Rails while referring to the article on the net, Since there were some stumbling points, I will summarize the general installation method as a memorandum.

table of contents

  1. Install rbenv
  2. Install Ruby
  3. Rails installation
  4. Reference

Install rbenv

Clone rbenv from git.

$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv

By installing a plugin called ruby-build, You can install Ruby in rbenv.

$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

Write the settings in .bashrc so that you can use rbenv.

=> Add rbenv path to environment variable PATH.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

=> Initialize rbenv.

$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Ruby installation

Check the version of ruby that can be installed.

$ rbenv install --list-a

1.8.5-p52
1.8.5-p113
1.8.5-p114
1.8.5-p115
1.8.5-p231
1.8.6
1.8.6-p36
1.8.6-p110
1.8.6-p111
1.8.6-p114
  :
  :

Install ruby.

$ rbenv install 2.5.7

If the following error is displayed, install the package according to the error log, and then Install ruby.

error: install `curl`, `wget`, or `aria2c` to download packages
error: failed to download ruby-2.5.8.tar.bz2

BUILD FAILED (Ubuntu 18.04 using ruby-build 20200520)

$ apt install wget

If you see the following error, please install the related packages of rbenv and then Install ruby. * I was able to fix the error by installing all of this package, You may not need to install all the packages listed here ... If you find a package you don't need, we'll fix it later. </ font>

configure: error: in `/tmp/ruby-build.20200530061452.7106.ZgOAgp/ruby-2.5.7':
configure: error: no acceptable C compiler found in $PATH
$ apt update
$ apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev

Confirm that ruby is installed.

$ ruby versions

Set ruby to global or local.

$ rbenv gloval 2.5.7
$ rbenv local 2.5.7

Make sure ruby is set to global or local.

$ ruby --version

Rails installation

Install the required packages for rails. libsqlite3-dev is required when installing Rails nodejs is required when starting Rails

* Maybe you also need to install sqlite3 ... </ font>

$ apt install libsqlite3-dev nodejs

Install rails. You can specify the version with the -v option.

$ gem install -v 5.2.2 rails

Make sure rails is installed.

$ rails --version

Project generation

$ rails new hoge_project

reference

Let's build a Ruby on Rails environment on ubuntu! Install Ruby on Ubuntu 18.04 using rbenv

Recommended Posts