Ruby on mac not installing gem showing permission denied - ruby

I am trying to install a ruby gem in My Machine using xcode where I call a shell script.
cd "/Users/Desktop/gemfolder"
gem install somegem.gem
I am getting an error like this:
While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Gems/1.8
Any workaround for it I am a newbie to ruby so don't know what to do anyhelp will highly appreciated.

Being sudo might fix your problem, however when you are installing gems , its not a good idea to install them as sudo, so the preferred way of installing ruby on any machine is to install rvm (Ruby Version Manager) first and then install your ruby version.
Main advantages of having a ruby version manager are,
1 - allows you to install multiple ruby versions side by side
2 - allows you to install gems for each ruby version (via gemsets)
So to install rvm in your mac, check here
list of ruby version managers

Related

Can't install Ruby Compass on Mac Big Sur 11.5.2

I'm trying to get Compass installed on a 2020 Mac Book Pro running Big Sur (11.5.2).
When I try and run:
gem install compass
I get the error:
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory
If I try and run:
sudo gem install compass
I get the error:
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.4/ext/ffi_c
I've tried installing and updating Ruby.
I've tried updating the system Ruby, but the system doesn't allow a more recent version than the below:
Updating rubygems-update
Fetching rubygems-update-3.3.3.gem
Successfully installed rubygems-update-3.3.3
Parsing documentation for rubygems-update-3.3.3
Installing ri documentation for rubygems-update-3.3.3
Installing darkfish documentation for rubygems-update-3.3.3
Done installing documentation for rubygems-update after 206 seconds
Parsing documentation for rubygems-update-3.3.3
Done installing documentation for rubygems-update after 0 seconds
Installing RubyGems 3.3.3
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted # rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem
% ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
Not sure what to do or try next.
Anyone have any ideas on how to get Compass installed?
This really decomposes to two issues, as you noticed with the sudo call.
(1) You're trying to write gems to the protected directory for your system Ruby.
In most development environments, it's best to install a Ruby version manager that allows you to install multiple Rubies side-by-side for different projects. Purely subjectively, I'd recommend rbenv to manage only Ruby, or asdf to manage Ruby versions along with other languages versions. However, the question of which Ruby version manager to use is very well tread already, so you can pick the solution that's best for your needs with existing information.
(2) You're installing a gem with native extensions, which means that you need the underlying C libraries installed on your system to build correctly (assuming you're using CRuby, the default Ruby implementation). You'll need to install libffi-dev on your machine to build that gem correctly. Based on this question, it seems a simple brew install libffi should work for that.
Lastly, I'll suggest that it's idiomatic to use the bundler gem to manage gems per-project with Ruby. I'd reconsider if you really want to run this gem system-wide, or if it might vary versions across multiple projects.

using compass with RVM and installed native ruby?

I am facing a issue with RVM and installed ruby debian/ubuntu package.
As long as I have only installed RVM every works fine. I can use the ruby version which is provided/installed by RVM. Also if I install a gems package compass everything works fine. The RVM is installed as recommended by RVM as single user.
As soon as I install a ruby ubuntu package (which is mandatory for some other ubuntu packages and I have not a option to remove it) my RVM configuration is broken. I cannot execute anymore the compass (command not found) also trying to install it once again with
gem install compass
I am getting
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /var/lib/gems
Also
which ruby
which gem
Points to /usr/bin and not to my home?!?
Even if I have set
PATH=/home/rocky/.nvm/v0.10.38/bin:/home/rocky/.rvm/bin:...
I have no clue where to take a look since I am very new to ruby and to RVM. Hope someone can help me?
I am getting Permission denied - /var/lib/gems
/var/lib/gems is owned by root therefore you need to do:
sudo gem install compass
which ruby Points to /usr/bin and not to my home?!? Even if I have
set
This is probably because rvm is not running. Try this:
source ~/.rvm/scripts/rvm
which ruby
Note: Once rvm is loaded correctly, which ruby will point to different location and first question may no longer persist (and so do using sudo).

Installing gem fails with permissions error [duplicate]

This question already has answers here:
How to install a gem or update RubyGems if it fails with a permissions error
(32 answers)
Closed 7 years ago.
I updated my Mac OS to 10.9 Mavericks yesterday. My current Ruby version shows as
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
I got Rails installed on my machine and when I try to install gems I get the following message:
Fetching: eventmachine-1.0.3.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I am trying all this in my home directory. Any suggestions?
Use a Ruby version manager, like RVM or rbenv.
I can't speak for rbenv, but RVM prepends a Ruby version-specific bin to your PATH that you have access to, so you don't have to use sudo (which is how you could install gems in your current situation, but is highly discouraged).
rbenv similarly prepends to your $PATH, but it uses a shim.
When I had this same error it was because I did not have a Ruby version manager installed, it defaulted to the Ruby version that came shipped with my computer which is owned root.
Since it is a very bad idea to use sudo to install gems, I installed RVM with Ruby 2.1.2
\curl -sSL https://get.rvm.io | bash -s stable --ruby=2.1.2
then made sure that it was being used as the default by running
rvm use ruby-2.1.2
RVM creates a new location to store your Ruby and gems with your user permissions so you don't have to use sudo or get a permissions error. The new gem location is:
~/.rvm/gems
Then carry on as you were...
gem install ....
I do not have RVM installed. I got this error because I installed rbenv but did not run rbenv init yet.
After I inserted the contents from the command rbenv init into .bash_profile, gem install works as expected.
I also happened to set rbenv global <ruby-version> to a downloaded Ruby version first.
Just like to say to you all after wasting a good hour or more on trying to install RubyGems... to rubygems-2.4.5 'sudo' got me through!
It works a treat...

Error installing rubygems

I get the following error when trying to install rubygems version 1.3.7
~/Downloads/rubygems-1.3.7
$ ruby setup.rb
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/gem
Any idea what is cause this. I've previously installed RVM.
Thanks
Run the command
sudo !!
Rather than mess with your system installation of Ruby, consider using RVM to manage your Ruby installation(s). RVM will install multiple Rubies on demand, allow you to create various gem sets, copy them between versions of Ruby, all while sandboxing your Ruby installation in ~/.rvm.
Installing RVM

Having issues installing ruby gems after latest OS X El Capitan update

After the latest update it appears a few of my gems have been affected and are either missing/changed.
In particular the gem 'rubocop' is giving me issues as I use atom for a text editor and I have flags popping up.
"Failed to spawn command rubocop. Make sure rubocop is installed and on your PATH"
"Error: spawn rubocop ENOENT"
I've tried re-installing the rubocop gem through the command line and I'm running into this issue:
gem install rubocop
Fetching: rainbow-2.1.0.gem (100%)
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Gems/2.0.0/rainbow-2.1.0.gem
I've even tried to uninstall the gem but there's no output after running gem uninstall rubocop
I really have no idea where to begin to resolve this and I'd love any help possible!
Make sure you add sudo before gem install rubocop
And then go to documentation of rubocop to check which version of ruby it takes to run.
You can also install rbenv.its better then rvm (they are ruby version managers your can put multiple versions of ruby on same machine using them)
if further you need help .. let me know !
happy coding
Don't forget that installing things into the system Ruby requires sudo privileges, /Library is usually restricted access.
Installing your own personal Ruby with rvm or rbenv avoids all this.

Resources