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.

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:

/var/lib/

This is secure by design.

sudo

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.

chmod

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.

Alt

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

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 - Kodlogs.net) 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!

Hi

Here I am in 2023. Same error:

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

Maybe it’s time to update Quickstart | Jekyll • Simple, blog-aware, static sites ?

Year 2024 - I have the same error…

And it’s 2026, and I have the same issue.

The most logical solution would seem to be having the cache in /tmp instead of /var/lib, but I tried BUNDLE_CACHE_PATH=/tmp/bundler bundle install and still it tried to write into /var/lib. Does anyone have recommendations for how to install Jekyll without needing to mess with root-owned directories?

I had a similar issue on MacOS. Also 2026.

What seemed to be my issue, and it seems like this is also an issue for Ubuntu then is that when I use the Ruby version installed by the system, it tries to install into libraries where it doesn’t have permissions.

Updating Ruby to another version like v3.x solves this because it installs Ruby on the user level.

This helped me, not sure if it will help you as well.

If this is a common theme, it might make sense to update the docs?

More than a Ruby issue is how the gem executable works.

It is a package manager and just like any package manager, it tries to put everything available to everyone (think of apt, zypper, yum…).

Let’s remind that we use gem to install libraries, but in many cases, and jekyll is among them, we also get executables that need to be run from a certain path, otherwise you would never see it from the command line.

To overcome that situation, you can install a Ruby version manager that manages the system gems installed by default in that reserved path and those you install under the home folder, and lets you switch between several Ruby versions.

Otherwise use the --user-installflag while using the gem command.

gem install –user-install jekyll

If you don’t want to repeat that flag every time, you can configure a .gemrc file under your home folder, appending these lines:

install: --no-rdoc --no-ri --env-shebang --no-format-executable --user-install update: --no-rdoc --no-ri --env-shebang --no-format-executable --user-install

Another flag to take in consideration is --no-format-executables, it just avoids to append the ruby version on any executable installed by gem.

Personally I used `rvm` with Ruby v2.x, but switching to Ruby v3 I prefered get rid of any of these tools because things started to be too complicated, aka none of them was working as I wanted.