Issue with permissions while installing gems on Ubuntu 16.04
Issue:
I followed jakyll installation tutorial starting from ruby installation on Ubuntu 16.04:
# apt install ruby
But after that it’s not possible to istall gems without root permissions:
$ gem install jekyll
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.3.0 directory.
Solution:
Remove ruby with the package manager:
# apt-get remove ruby
Install required dependencies:
# apt-get update
# apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
Install rbenv:
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ exec $SHELL
Install ruby-build plugin for rbenv:
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
$ exec $SHELL
Install latest ruby and set it as default:
$ rbenv install 2.4.2
$ rbenv global 2.4.2
Verify installation:
$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
Install jakyll with non-root permissions:
$ gem install jekyll