You don't have write permissions for the /var/lib/gems/2.3.0 directory

This seems to be a fairly common problem, evidenced by Googling. I have installed Jekyll quite a few times on Windows but this was on a clean install of Ubuntu 16.10…

jack@jakobuntu:~$ gem install jekyll
Fetching: public_suffix-2.0.5.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /var/lib/gems/2.3.0 directory.

You’d have to use rvm for Ruby and then install gems. Another and unsecure method is to use sudo, but don’t do that.

Thanks but not so sure what it means. I did a fresh Ubuntu install this evening and exactly the same issue again. Can an expert pls help fix this bug?

This is not a bug. Only root (administrator) can install stuff to /var/lib, but doing this is not recommended. You need to use Ruby Version Manager (rvm) or Bundler to create user based installation.

For installation examples see this (rvm) or this (bundler).

Thanks heaps for clarifying that. I am confused however about why the default install instructions for Jekyll don’t mention this. Surely many people are using Ubuntu without being root?

I don’t see this as something for Jekyll to define. It hits me more as a Ruby environment setup than anything.

1 Like

How would one use rvm or another program to fix this issue? Especially as someone who maybe does have as much experience?

Its definitely a common issue, and a quick google search will show you a multitude of solutions that don’t work, or are outdated to Jekyll.

I don’t think introducing rvm is a good idea as it is another tool to learn and manage.

The comment as above is that the user does not have access to write to here, only read:


This is secure by design.


One option as mentioned above is

sudo gem install GEM

But that is insecure and not recommended. For example, some malicious code in the gem or a subdepedency could install malware or wipe the hard drive, using root access.


An alternative, if you have the ability to run sudo, is to allow all users other than root to write to that gems directory.

sudo chmod +w /var/lib

You might have to run that on gems with that or use a recursive flag.

Then, without sudo, install there.

gem install GEM

While that command can’t wipe your hard drive or anything else as root, it can install malicious software in that shared directory across users.

User level

The safest without having to use sudo at all is:

gem install GEM --user-install

Which installs to somewhere like ~/.gem depending on your OS or version or Ruby.

And it keeps your user’s gems independent of the root gems or shared gems.

Local project

I would avoid installing Jekyll using the gem command. As then you have a global Jekyll that might clash between projects that need 3.8 or 3.9 or 4.1

So rather add Jekyll to project specific gems in Gemfile

bundle add jekyll

That will add to Gemfile and install Jekyll.


BTW the Mac instructions suggest passing a flag -n to install in /usr/local/bin

PS consider upgrading your Ruby from 2.3 to 2.7 or 3.0

You can also do

sudo chown -R /var/lib/gems myuser

So that your user owns that and doesn’t need sudo to edit it.

If you are the only person who users the machine, chown and chmod approach choice doesn’t make a difference

1 Like

I keep reading a lot of posts when I first get into trouble. This is how I once reached this website (You Don't Have Write Permissions For the /library/ruby/gems/2.3.0 Directory - and got the desired solution. You can read this post as well as visit here. I think it will be very useful for you

After a lot of research and tries, that is the only way that allowed me to install gems, finally, thank you!

I just had to change your command by sudo chown -R myuser /var/lib/gems and repeat this command to give permission to another directory and then voilà, done installing!