Can't install Ruby Compass on Mac Big Sur 11.5.2 - ruby

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.

Related

Installing into parent path not allowed when installing locally built Ruby gem

I've written a Ruby gem that I'd like to install locally. I'm using Rubygems 3.0.6 and RVM on OS X Mojave. This is a closed source gem and I'd rather not go to the trouble of publishing it to the company gemservers. I'm able to install other (published) gems just fine using both bundle install and gem install.
The gem is all built (using gem build) and the code works, but when I run:
gem install influx_trello_utility-0.1.0.gem
I get an error:
ERROR: While executing gem ... (Gem::Package::PathError)
installing into parent path /bin/[ of /Users/danascheider/.rvm/gems/ruby-2.6.3#influx_trello_utility/gems/influx_trello_utility-0.1.0 is not allowed
Any help with this would be much appreciated. I'm not sure what additional information would be useful, but I'm happy to answer any questions you may have. Thanks!

Getting an error when installing 'sudo gem install mechanize'

Even I have installed ruby-dev and ruby-make but still giving same error ? how to fix the error ?
sudo gem install mechanize
Building native extensions. This could take a while...
ERROR: Error installing mechanize:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.4.0/gems/unf_ext-0.0.7.5/ext/unf_ext
/usr/bin/ruby2.4 -r ./siteconf20180417-8728-15wdd1s.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.4.0/gems/unf_ext-0.0.7.5 for inspection.
Results logged to /var/lib/gems/2.4.0/extensions/x86_64-linux/2.4.0/unf_ext-0.0.7.5/gem_make.out
You don't have the source code for Ruby so when it attempts to compile the gem it fails. It's looking for /usr/lib/ruby/include/ruby.h but that file isn't present on your system.
Generally, it's not a good idea to use the system version of Ruby. (for this reason, and others) You should use a Ruby manager to install Ruby into your user profile, as this will make compiling gems a lot easier.
For example, you can use RVM to install Ruby:
\curl -sSL https://get.rvm.io | bash -s stable
This will install the latest version of rvm, which you can then use to install Ruby 2.4:
rvm install 2.4
You can install nearly any version of Ruby by specifying its version, for example Ruby 2.5:
rvm install 2.5
Afterwards, running ruby will automatically run the version installed by RVM. And since it's installed in your profile, you don't need to use sudo for any operations. (and you should never use sudo when using rvm or Rubies installed by rvm)
In your case, you would then be able to run gem install mechanize successfully because it would be using the Ruby installation in your home directory that includes a copy of the source code and header files.
If for some reason you can't use RVM or don't want to use RVM, then you need to have the Ruby header files installed. The way to install these headers varies by operating system so there's no one answer I can give you. If your OS is a Debian-based version of Linux, for example, you can install the headers with:
sudo apt-get install ruby2.4-dev
More information is available in another answer on stackoverflow.

Ruby Error installing af: failed to build gem native extension

I wanna deploy my grails application on AppFog. To do this, I've installed Ruby 22 x64 and devkit mengv64. I've extracted devkit.7z to C:\ruby, done commands: dk.rb install,dk.rb init. Then, I entered a command: gem install af,
but I got such error: Error installing af: failed to build gem native extension. How to fix it?
There is often an issue with the escape_utils gem. This a general limitation of RubyGems. If there's a problem with a gem dependencies, new installs of the af gem or updates to any of its gem dependencies can screw things up. That's why AppFog v2 is testing a binary executable to avoid this mess.
That being said, the general practice for installing on Windows is to install the Ruby environment you want and install the appropriate dev kit. When that's done, you'll need to find the Ruby Enabled Command Prompt. Usually, Start > Programs > Ruby*. Everything below should now be done from there:
ruby dk.rb install
ruby dk.rb init
gem update --system
gem install escape_utils -v 1.0.1
This gem regularly has problems, especially for Windows, so this is usually the best version to go with for the time being.
gem install af
Here's AF's article for installing the gem on Windows: Installing the AF CLI Tool on Windows.
Either the App Fog gem requires a native extension, or one of its dependencies does.
Does the error show which gem is failing?
According to RubyGems, there are some dependencies. I don't see which one would require a native extension.
So, you may want to try installing the dependencies and see if one of them fails.

Ruby on mac not installing gem showing permission denied

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

Updating Ruby to 2.0.0 using Pik

After installing pik and changing my Ruby version to 2.0.0, bundler no long works properly
C:\Users\Me\Documents\Work Projects\Application>bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.8.0)
Installing atomic (1.1.14)
Gem::InstallError: The 'atomic' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occurred while installing atomic (1.1.14), and Bundler cannot continue.
Make sure that `gem install atomic -v '1.1.14'` succeeds before bundling.
Installing the devkit from Ruby Installer sort of defeats the reason why I went to the trouble of installing pik. How can I fix this, so that in the future, I can easily update ruby using pik and still have everything working?
I had the same problem - if you follow the instructions listed (ie installing devkit and following their directions [they don't actually tell you to use rubyinstaller]), you'll be fine. Also make sure that during the init phase of the Devkit instructions that it doesn't miss any of your ruby installations.
A note though, it seems that pik can't specify the x64 version of 2.0.0, so you may run into problems if that's the case. In the end I had to use the rubyinstaller for the x64 version of ruby, and then ran the x64 version of the devkit.
Hope this helps.
I think Josh' answer is probably right, but I actually installed Ubuntu as a VM in the end, just so I could use RVM.
RVM is a thousand times better than Pik, and it installs the DevKit. It's so good it's genuinely worth installing Ubuntu just so you can use it.

Resources