Why Do I Get a "Permission Denied" Error While Installing a Gem

Why do I get a permission denied error while installing a gem?

Your Ruby is installed in /usr/local/Cellar/ruby/....

That is a restricted path and can only be written to when you use elevated privileges, either by running as root or by using sudo. I won't recommend you run things as root since you don't understand how paths and permissions work. You can use sudo gem install jekyll, which will temporarily elevate your permissions, giving your command the rights needed to write to that directory.

However, I'd recommend you give serious thought into NOT doing that, and instead use your RVM to install Ruby into your own home directory, where you'll automatically be able to install Rubies and gems without permission issues. See the directions for installing into a local RVM sandbox in "Single-User installations".

Because you have RVM in your ~/.bash_profile, but it doesn't show up in your Gem environment listing, I suspect you either haven't followed the directions for installing RVM correctly, or you haven't used the all-important command:

rvm use 2.0.0 --default

to configure a default Ruby.

For most users, the "Single-User installation" is the way to go. If you have to use sudo with that configuration you've done something wrong.

Getting permission denied error when I run gem install bundler

you are using the system's ruby and now you need to root level permission to to install bundler. Sudo enables root privileges. Check if your account has root privileges.

I prefer using a version and manager like rbenv. Install rbenv . then install the required version of ruby and then install bundler.

Permission denied error while installing gem

Installing C-extensions on Windows has always been a big and painful problem, as Windows doesn't ship with a compiler. Most gems which are intended to be used on Windows systems publish a specialized gem version with a specific platform field, which then would include pre-compiled binaries. This is not the case for rackamole, otherwise it would be visible here.

Another solution would be to use a version of the gem which uses the newer FFI approach instead of C-extensions to interface with native libraries. I guess this isn't an option here because rackamole, whatever that is, is probably only available with C-extensions.

There once was a Ruby distribution including its own compiler and development headers, but I can't remember the name and I don't know if its still maintained.

Should using Windows not be mandatory, I recommend using a more developer-friendly OS like Ubuntu or Debian in combination with rvm.

Is there a reliable way to avoid permission denied errors when installing Ruby gems with native extensions on Windows Subsystem for Linux?

The problem that I'm experiencing may be related to Visual Studio Code's file watching. It is reflected in two GitHub issues against WSL - 1956 and 3395. Visual Studio Code has remote.WSL.fileWatcher.polling, which can be enabled which works around this issue. However, the documentation states that there is a performance impact for large workspaces and it may be necessary to also adjust the remote.WSL.fileWatcher.pollingInterval setting. WSL2 will resolve these issues.

Since enabling this flag, I haven't seen the error while working with VS Code running.


Now that WSL2 is out, I was able to disable this flag and the issue has not reappeared. It appears that if you can upgrade to WSL2, that may be a preferred solution. However, for anyone who hasn't yet upgraded or can't upgrade, toggling the remote.WSL.fileWatcher.polling and remote.WSL.fileWatcher.pollingInterval should be good.



Related Topics



Leave a reply



Submit