Reputation: 6053
I have checked all the other similar answers and none was exactly like mine, neither did any of those solutions work for me.
gem environment
and sudo gem environment
give the same result:
RubyGems Environment:
- RUBYGEMS VERSION: 1.5.3
- RUBY VERSION: 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- /home/ava/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
rvm -v
: rvm 1.22.3
ruby -v
: ruby 1.8.7
OSX 10.8.4
echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/ava/.rvm/bin:/home/ava/bin
gem install <gem-name>
gives
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/local/lib/ruby/gems/1.8 directory.
whereas I am able to install the same via sudo. What am I doing wrong?
UPDATE:
As per comments and this post, I ran following:
rvm implode
and then re installed the stable version.
rvm install 1.9.3
or any other ruby installation fails with
Error running '__rvm_make -j24',
please read /home/ava/.rvm/log/log/1378418790_ruby-1.9.3-p194/make.log
There has been an error while running make. Halting the installation.
make.log
[2013-09-05 22:06:48] make
current path: /home/ava/.rvm/src/ruby-1.9.3-p194
command(2): make -j24
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Werror-implicit-function-declaration -fPIC
XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
CPPFLAGS = -I. -I.ext/include/x86_64-linux -I./include -I.
DLDFLAGS = -Wl,-soname,libruby.so.1.9
SOLIBS = -lpthread -lrt -ldl -lcrypt -lm
compiling main.c
compiling dmydln.c
compiling dmyencoding.c
compiling version.c
compiling miniprelude.c
compiling array.c
compiling bignum.c
compiling class.c
compiling compar.c
compiling complex.c
compiling dir.c
compiling dln_find.c
compiling enum.c
compiling enumerator.c
compiling error.c
compiling eval.c
compiling load.c
compiling proc.c
compiling file.c
:
:
:
In file included from ossl.h:213,
from ossl_pkcs5.c:5:
openssl_missing.h:71: error: conflicting types for ‘HMAC_CTX_copy’
/usr/local/include/openssl/hmac.h:102: error: previous declaration of ‘HMAC_CTX_copy’ was here
openssl_missing.h:95: error: conflicting types for ‘EVP_CIPHER_CTX_copy’
/usr/local/include/openssl/evp.h:459: error: previous declaration of ‘EVP_CIPHER_CTX_copy’ was here
make[2]: *** [ossl_pkcs5.o] Error 1
In file included from ossl.h:213,
from ossl_x509req.c:11:
:
:
:
Upvotes: 88
Views: 178797
Reputation: 2718
As Mac user the below was straight forward
❯ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
❯ brew install ruby
❯ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
❯ source ~/.zshrc
❯ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
❯ source ~/.bash_profile
Upvotes: -1
Reputation: 171
Macbook M1 and newer :
Open Terminal
curl -L https://get.rvm.io | bash -s stable
Reopen Terminal
rvm install ruby-3.1.1
rvm use ruby-3.1.1
rvm --default use 3.1.1
Then this installed cocoapods as expected
sudo gem install cocoapods
Upvotes: 17
Reputation: 12677
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
.zshrc
, .bashrc
etcexport GEM_HOME="$HOME/.gem"
gem i LIBRARY_NAME
Upvotes: 135
Reputation: 14823
sudo
I was using asdf
version manager. I was trying to install cocoapods
for Flutter. Originally I had sudo
installed the gem, then I read in the documentation that I should install without sudo
for version managers, so I tried uninstalling it and then reinstalling it without sudo
, but was receiving this error:
╰─❯ gem install cocoapods Successfully installed cocoapods-1.11.3 ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Users/coder/.asdf/installs/ruby/3.1.0-dev/lib/ruby/gems/3.2.0+0/doc/cocoapods-1.11.3 directory.
I navigated to the directory listed above and deleted the empty folder.
Then I was able to run: gem install cocoapods
without any errors.
Unfortunately flutter doctor
still seems to be upset about the availability of cocoapods 🤷
flutter doctor
It seems that it wasn't liking Ruby v3.2, and it was odd because asdf
showed that I had v3.1 which was confusing. I decided to install Ruby v2.7.4 then just gem install cocoapods
now flutter doctor
is all green 🎉
Upvotes: 0
Reputation: 311
It depends on the context. For example if you are running this from a Jenkins perspective things dont work the same way as when firing up a bash shell and giving gem or bundle instructions. I got the same error when Jenkins but failed to realize that Jenkins has his own way of figuring out the PATH so things may not work well there unless you find the proper jenkins config field to fill in related information for .. wherere is ruby for example. Otherwise you may end up issuing symbolic link commands to link where the machine understands the executables..
Upvotes: 0
Reputation: 21
I tried to update my ruby to the newest version use brew ruby install
and after I got my latest ruby version , gem install rails will work
Upvotes: 0
Reputation: 8056
The "write permissions" errors and Gem::FilePermissionError
mentioned here are due to an improperly configured Ruby environment. You should never need to use sudo
to install gems, no matter how many times you see it as an accepted answer on Stack Overflow. Here's why.
At a high level, setting up a proper Ruby development environment on a Mac involves six steps:
~/.bash_profile
or ~/.zshrc
) - each manager will have instructions for doing this, and this is a typical step that people missMy personal preference is chruby with ruby-install. For more details and a script that can automate this whole process, check out my answer here: https://stackoverflow.com/a/54873916/928191
Upvotes: 7
Reputation: 1106
If you use rbenv
, it's possible that you forgot to enable it with something like:
> rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:
eval "$(rbenv init -)"
Upvotes: 3
Reputation: 23746
If you have just installed rvm
, and you are getting error like this
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
remember to call
source ~/.bash_profile
to make sure that gems are installed in ~/.rvm
Then you can simply
rvm use 2.6.6
gem install yourgem:2.0.1
Upvotes: 0
Reputation: 1
ok after trying all the different solutions above, none of them worked for me. So for those who will encounter it in the future please know this. the solution could have nothing to do with cocoa pods but more with Xcode new versions. as you update the new version you need to agreed with the new terms and conditions. you can do so directly in the terminal. Run : sudo xcode-select -s /Applications/Xcode.app/Contents/Developer and than: sudo xcodebuild -license than press space till you arrive at the button and finally type agree From than can try again to add cocoapods with simply : gem install cocoapods
Upvotes: 0
Reputation: 81
If you have installed rbenv & facing this error, below answer will help (this is how it worked for me)
Issue:
$ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
DO NOT USE SUDO
$ rbenv versions
* system (set by /Users/user/.rbenv/version)
2.3.8
Here, you can see, by default it selected system. change it to your ruby version.
$ rbenv global 2.3.8
$ rbenv versions
system
* 2.3.8 (set by /Users/user/.rbenv/version)
Then try installing the bundler, it will work:
$gem install bundler -v 1.17.3
Fetching: bundler-1.17.3.gem (100%)
Successfully installed bundler-1.17.3
Parsing documentation for bundler-1.17.3
Installing ri documentation for bundler-1.17.3
Done installing documentation for bundler after 5 seconds
1 gem installed
Upvotes: 8
Reputation: 4373
I run into a similar problem on my Mac while trying to install watchr package
ERROR: While executing gem ... (Gem::FilePermissionError)
Somehow running sudo every time I need to install a package felt excessive. I have rbenv installed so I set global ruby version like this
rbenv global 2.6.5
Then simply installed the package I wanted. In my case the command is
gem install watchr
Upvotes: 0
Reputation: 1
I encountered the same error yesterday when I tried to install rails using following command.
$ gem install rails -v 4.2.3
Prior to this I had installed Ruby Environment Manager (rbenv), but the following command failed to add the if-eval to bash profile.
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> -/.bash_profile
So, I looked into this and found out that the current directory reference - was the problem for the above command to fail. I changed it to ~ and successfully ran the below command
$ echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
After this I was able to install the rails gem successfully (without needing to do sudo)
Upvotes: 0
Reputation: 211590
If you have installed rvm
as the root user, then you must sudo
to install anything.
You can install rvm
in user-mode as a regular user, in which case everything is stored in your home directory and no sudo
is required.
If you are not committed to this particular install, type sudo rvm implode
and start over.
Upvotes: 27
Reputation: 1482
Your global (system-wide) config file probably has the --no-user-install
flag set. Create/edit your local ~/.gemrc
file and append the following line(s):
:gemdir:
- ~/.gem/ruby
install: --user-install
Note
The actual directory for the gemdir
option will vary depending on your system/desire; it may or may not be needed, but it's probably better to designate the desired installation directory within your home
folder (gemdir
) than to assume it'll be taken care of by itself.
The ArchLinux Wiki has some useful/well-organized information pertaining to this.
Alternatively, similar to the rvm
solution already suggested, you can try using chruby to maintain, configure, and use local versions of ruby
. To install additional versions of ruby
, however, you need to use ruby-install.
$ brew install chruby ruby-install
$ ruby-install ruby 2.4.0
$ echo "source /usr/local/opt/chruby/share/chruby/chruby.sh" >> ~/.bash_profile
$ echo "chruby ruby" >> ~/.bash_profile
# Do this to select the default alternative ruby installation, assuming
# there is no other version installed.
$ chruby ruby
## Otherwise, list the available ruby versions installed, and select
$ chruby
ruby-2.3.0
ruby-2.4.0
$ chruby ruby-2.4.0
From the project's README:
Changes the current Ruby. Features
Updates $PATH. Also adds RubyGems bin/ directories to $PATH. Correctly sets $GEM_HOME and $GEM_PATH. Users: gems are installed into ~/.gem/$ruby/$version. Root: gems are installed directly into /path/to/$ruby/$gemdir. Additionally sets $RUBY_ROOT, $RUBY_ENGINE, $RUBY_VERSION and $GEM_ROOT. Optionally sets $RUBYOPT if second argument is given. Calls hash -r to clear the command-lookup hash-table. Fuzzy matching of Rubies by name. Defaults to the system Ruby. Optionally supports auto-switching and the .ruby-version file. Supports bash and zsh. Small (~100 LOC). Has tests.
Anti-Features
Does not hook cd. Does not install executable shims. Does not require Rubies be installed into your home directory. Does not automatically switch Rubies by default. Does not require write-access to the Ruby directory in order to install gems.
Requirements
bash >= 3 or zsh
Upvotes: 47
Reputation: 1
Be aware that if you chose to perform a multi-user install of rvm, you must add each user to the rvm group via
usermod -a -G rvm <USERNAME>
Relevant info from rvm's FAQ
Upvotes: 0
Reputation: 772
To resolve the error:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /usr/local/lib/ruby/gems/1.8 directory.
the following solution worked for me:
sudo gem install -n /usr/local/bin cocoapods
Upvotes: 61
Reputation: 167
assuming that rvm is installed you could do something like:
$ rvm install 2.1.1
$ rvm @global do gem install compass
No need to do sudo.
Upvotes: 4
Reputation: 111
You probably don't have write permissions to somewhere along that path, (most likely /usr/local/lib), you need to change the location of your RVM storage in order to not need sudo
Upvotes: -1