I am trying to install rails , in order to install cocoapods but I am having some trouble with permissions.
I tried $ $sudo chown -R username /usr/ but operation is now allowed.
Username-MacBook-Pro:~ username$ $sudo gem install rails
Building native extensions. This could take a while...
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # dir_s_mkdir - /usr/local/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14
Username-MacBook-Pro:~ username$
You should not install rails with the sudo command for two reasons:
I made this mistake in the past and then I had issues when installing and using other gems because of inconsistencies with permissions. It might very likely cause you the same trouble.
The concern of whether or not to install rails with the sudo command is addressed and well explained in a different post: 'sudo gem install' or 'gem install' and gem locations
The reason why installing gems with sudo is worse than just gem install is because it installs the gems for ALL USERS as root. This might be fine if you're the only person using the machine, but if you're not it can cause weirdness.
I recommend that you install rvm first and then rails. Here is a great tutorial that walks you through the process: http://railsapps.github.io/installrubyonrails-mac.html
Related
I'm tryng to install rails with gem install rails but when I try that I get
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
So I tried using sudo gem install rails and I get
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
I've checked on the internet and it says I should install RVM but when I try to do that it tells me :
Error running './configure --prefix=/Users/manhattan/.rvm/rubies/ruby-2.7.0 --with-opt-dir=/usr/local/opt/libyaml:/usr/local/opt/libksba:/usr/local/opt/readline:/usr/local/opt/zlib:/usr/local/opt/openssl#1.1 --disable-install-doc --enable-shared', please read /Users/manhattan/.rvm/log/1589107425_ruby-2.7.0/configure.log There has been an error while running configure. Halting the installation.
Could someone help me please.
Installing Ruby gems (like Rails) on a Mac is a common source of confusion and frustration. Unfortunately, most solutions are incomplete, outdated, and provide bad advice. You should never need to use sudo or change permissions.
I wrote an article explaining why you should never use sudo to install gems.
This write permissions error is very common, and is due to trying to install Rails using the system Ruby (the version of Ruby that came preinstalled on your Mac). Learn why you shouldn't use the system Ruby to install gems on a Mac.
There are many questions on Stack Overflow about this permissions error, and the solution is the same. So, instead of repeating myself, I'll just link to my popular answer (480+ votes) here:
https://stackoverflow.com/a/54873916/928191
you can change the permission of the directory you are working on
# chmod -R 777 DIR_NAME
# cd DIR_NAME
# gem install rails
I am new to programming and am trying to get rails installed on my terminal. I have been following instructions from a friend, installing the xcode command line tools, homebrew, git, rbenv, ruby-build, ruby gems, ruby, and postgres. But whenever, I try $gem install rails, I get the following:
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ gem install rails
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
This is especially frustrating because when I run $gem list, it says I have rails 3.2.18. Which is peculiar, because when I run $rails v$, it tells me I have Rails 4.2.0.
When I try to use rails rails my new_app
Errno::EACCES: Permission denied # rb_sysopen - /Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rails-4.2.0/README.md
An error occurred while installing rails (4.2.0), and Bundler cannot continue.
Make sure that `gem install rails -v '4.2.0'` succeeds before bundling.
run bundle exec spring binstub --all
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/shared_helpers.rb:83: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
bundler: command not found: spring
Install missing gem executables with `bundle install`
Russell-Silvers-MacBook-Pro:~ Russell_Silver$ bundle install
/Users/Russell_Silver/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/bundler-1.8.3/lib/bundler/vendor/thor/shell/basic.rb:355: warning: Insecure world writable dir /Users/Russell_Silver in PATH, mode 040707
Could not locate Gemfile or .bundle/ directory
This is really frustrating, especially for someone new to programming such as myself, so I am seeking help from anybody who might know what is wrong.
Your rbenv installation was incorrectly installed as it had elevated privileges which caused your user account to not have write access to ~/.rbenv.
Issue the following command in order to take of ownership of the directory:
sudo chown -R Russell_Silver ~/.rbenv
Note that some users may have a different rbenv directory, e.g. /usr/local/var/rbenv. This would take the place of ~/.rbenv in the above command.
First I installed rvm for multi-user using script
\curl -L https://get.rvm.io | sudo bash -s stable
and I added users to rvm group.
and rvm seems worked fine. so I installed ruby 1.9.3 and set 1.9.3 as default
and now I tried to install rails with command
gem install rails
It seems worked fine, but when fetching json-1.7.6.gem and an error occurs.
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p374/bin/ruby extconf.rb
creating Makefile
make
sh: make: Permission denied
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p374/gems/json-1.7.6 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p374/gems/json-1.7.6/ext/json/ext/generator/gem_make.out
So I thought it would be related with permission, so I tried
sudo gem install rails
but then this error occurs.
sudo: gem: command not found
What should I do?
use sudo as follows..
sudo gem install rails
Updated Answer:
our $PATH variable needs to include the exact path to your Ruby's bin directory. Adding a directory to the PATH does not include it's subfolders. Try adding the bin directory via:
export PATH=$PATH:/home/adam/.gem/ruby/1.8/bin
or if you installed the gem using sudo:
export PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
You might want to add this to your .bashrc file, so that you don't have to set this manually every time your open up a new bash.
you can use rvmsudo to run sudo commands. But you should really be using Gemfiles to install gems using Bundler.
I have tried everything from source installations, homebrew, and manually restoring the pg_config file as sudo user. I am out of ideas on this... here is what I get:
gem install pg -v '0.12.1'
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Users/Toran1/.rvm/gems/ruby-1.9.2-head/gems/pg-0.12.1/.gemtest
any help would be appreciated :).
Probably you ran sudo gem install pg to install pg, so the installed gem still has root permission. Run sudo chown -R Toran1 /Users/Toran1/.rvm to fix up the permission first. Then you should be able to run gem install pg
Manual gem installations like this can be installed with sudo.
sudo gem install pg -v '0.12.1'
Hope this helps!
EDIT:
As per the comments below, I noticed you are using rvm. Don't use sudo when using rvm. Check the paths and make sure that you do indeed have the correct permissions set!
use this:
RVMSUDO gem install pg
I am trying to set myself up on a mac to learn Ruby on Rails, however I seem to be having some problems. If I try to run commands such as ./script/server, i get this:
Rails requires RubyGems >= 0.9.4 (you have 0.9.2). Please gem update --system and try again.
When I run "gem update.." I get this:
Updating RubyGems...
Attempting remote update of rubygems-update
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /opt/local/lib/ruby/gems/1.8/cache/rubygems-update-1.3.0.gem
got it.
sudo gem update --system
Starting with El Capitan, Apple prevents user applications to modify /usr/bin for security reasons. So better install/update rubygems in the recommended folder, /usr/local/bin:
sudo gem update -n /usr/local/bin --system
(recommendation taken from https://stackoverflow.com/a/39928447/1033581)