Why can't I install Sass on Mac OS? [duplicate] - ruby

I am not able to install and run fakes3 gem on El Capitan Beta 5.
I tried:
sudo gem install fakes3
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fakes3
Then I tried doing it the cocoapods way. It worked for cocoapods but not for fakes3.
mkdir -p $HOME/Software/ruby
export GEM_HOME=$HOME/Software/ruby
gem install cocoapods
[...]
1 gem installed
gem install fakes3
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Disclaimer: #theTinMan and other Ruby developers often point out not to use sudo when installing gems and point to things like RVM. That's absolutely true when doing Ruby development. Go ahead and use that.
However, many of us just want some binary that happens to be distributed as a gem (e.g. fakes3, cocoapods, xcpretty …). I definitely don't want to bother with managing a separate ruby. Here are your quicker options:
Option 1: Keep using sudo
Using sudo is probably fine if you want these tools to be installed globally.
The problem is that these binaries are installed into /usr/bin, which is off-limits since El Capitan. However, you can install them into /usr/local/bin instead. That's where Homebrew install its stuff, so it probably exists already.
sudo gem install fakes3 -n/usr/local/bin
Gems will be installed into /usr/local/bin and every user on your system can use them if it's in their PATH.
Option 2: Install in your home directory (without sudo)
The following will install gems in ~/.gem and put binaries in ~/bin (which you should then add to your PATH).
gem install fakes3 --user-install -n~/bin
Make it the default
Either way, you can add these parameters to your ~/.gemrc so you don't have to remember them:
gem: -n/usr/local/bin
i.e. echo "gem: -n/usr/local/bin" >> ~/.gemrc
or
gem: --user-install -n~/bin
i.e. echo "gem: --user-install -n~/bin" >> ~/.gemrc
(Tip: You can also throw in --no-document to skip generating Ruby developer documentation.)

In my case, I had to re-install Ruby using Brew. That seems to have solved the problem as I can install gems again.
brew install ruby
After this, you need to log out and log back in, either graphically or just restarting your terminal.

That is because of the new security function of OS X "El Capitan".
Try adding --user-install instead of using sudo:
$ gem install *** --user-install
For example, if you want to install fake3 just use:
$ gem install fake3 --user-install

sudo gem install -n /usr/local/bin cocoapods
Try this. It will definately work.

You have to update Xcode to the newest one (v7.0.1) and everything will work as normal.
If after you install the newest Xcode and still doesn't work try to install gem in this way:
sudo gem install -n /usr/local/bin GEM_NAME_HERE
For example:
sudo gem install -n /usr/local/bin fakes3
sudo gem install -n /usr/local/bin compass
sudo gem install -n /usr/local/bin susy

Looks like when upgrading to OS X El Capitain, the /usr/local directory is modified in multiple ways :
user permissions are reset (this is also a problem for people using Homebrew)
binaries and symlinks might have been deleted or altered
[Edit] There's also a preliminary thing to do : upgrade Xcode...
Solution for #1 :
$ sudo chown -R $(whoami):admin /usr/local
This will fix permissions on the /usr/local directory which will then help both gem install and brew install|link|... commands working properly.
Solution to #2 :
Ruby based issues
Make sure you have fixed the permissions of the /usr/local directory (see #1 above)
First try to reinstall your gem using :
sudo gem install <gemname>
Note that it will install the latest version of the specified gem.
If you don't want to face backward-compatibility issues, I suggest that you first determine which version of which gem you want to get and then reinstall it with the -v version. See an exemple below to make sure that the system won't get a new version of capistrano.
$ gem list | grep capistrano
capistrano (3.4.0, 3.2.1, 2.14.2)
$ sudo gem install capistrano -v 3.4.0
Brew based issues
Update brew and upgrade your formulas
$ brew update
$ brew upgrade
You might also need to re-link some of them manually
$ brew link <formula>

As it have been said, the issue comes from a security function of Mac OSX since "El Capitan".
Using the default system Ruby, the install process happens in the /Library/Ruby/Gems/2.0.0 directory which is not available to the user and gives the error.
You can have a look to your Ruby environments parameters with the command
$ gem env
There is an INSTALLATION DIRECTORY and a USER INSTALLATION DIRECTORY. To use the user installation directory instead of the default installation directory, you can use --user-install parameter instead as using sudo which is never a recommanded way of doing.
$ gem install myGemName --user-install
There should not be any rights issue anymore in the process. The gems are then installed in the user directory : ~/.gem/Ruby/2.0.0/bin
But to make the installed gems available, this directory should be available in your path. According to the Ruby’s faq, you can add the following line to your ~/.bash_profile or ~/.bashrc
if which ruby >/dev/null && which gem >/dev/null; then
PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
fi
Then close and reload your terminal or reload your .bash_profile or .bashrc (. ~/.bash_profile)

This is the solution that I have used:
Note: this fix is for compass as I wrote it on another SO question, but I have used the same process to restore functionality to all terminal processes, obviously the gems you are installing are different, but the process is the same.
I had the same issue. It is due to Apple implementing System Integrity Protection (SIP). You have to first disable that...
Reboot in recovery mode:
Reboot and hold Command + R until you see the apple logo.
Once booted select Utilities > Terminal from top bar.
type: csrutil disable
then type: reboot
Once rebooted
Open terminal back up and enter the commands:
sudo gem uninstall bundler
sudo gem install bundler
sudo gem install compass
sudo gem install sass
sudo gem update --system
The the individual gems that failed need to be fixed, so for each do the following:
On my machine this was the first dependency not working so I listed it:
sudo gem pristine ffi --version 1.9.3
Proceed through the list of gems that need to be repaired. In all you are looking at about 10 minutes to fix it, but you will have terminal commands for compass working.
Screenshot

If the gem you are trying to install requires xml libraries, then try this:
sudo gem install -n /usr/local/bin <gem_name> -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
Specifically, I ran into a problem while installing the nokogiri gem v 1.6.8 on OS X El Capitan
and this finally worked for me:
sudo gem install -n /usr/local/bin nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
To make sure you have libxml2 and libxslt installed, you can do:
brew install libxml2 libxslt
brew install libiconv
and then check to make sure you have xcode command line tools installed:
xcode-select --install
should return this error:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

Reinstalling RVM worked for me, but I had to reinstall all of my gems afterward:
rvm implode
\curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm reload

I ran across the same issue after installing El Capitan, I tried to install sass and compass into a symfony project, the following command returned the following error:
$ sudo gem install compass
ERROR: Error installing compass:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for ffi.h... /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
So I then tried to install sass with:
$ sudo gem install sass
Got the same error message, after some googling I managed to install sass using the following command:
$ sudo gem install -n /usr/local/bin sass
The above worked for me with installing sass but did not work for installing compass. I read that someone somewhere had opened an instance of xcode then closed it again, then successfully ran the same command after which worked for them.
I attempted to open xcode but was prompted with a message saying that the version of xcode installed was not compatible with El Capitan.
So I then updated xcode from the app store, re-ran the following command which this time ran successfully:
$ sudo gem install -n /usr/local/bin compass
I was then able to run $ compass init
I now have all my gems working and can proceed to build some lovely sass stuff :)

I had to rm -rf ./vendor then run bundle install again.

You might have two options:
If you've installed ruby and rails, you can first try running the command:
rvm fix-permissions
You can uninstall ruby completely, and reinstall in your ~ directory aka your home directory.
If you're using homebrew the command is:
brew uninstall ruby
For rails uninstall without homebrew the command is:
rvm remove
This should reinstall the latest ruby by running command:
curl -L https://get.rvm.io | bash -s stable --rails<br>
Mac has 2.6.3 factory installed, and it's required... if not run this command:
rvm install "ruby-2.6.3"
and then:
gem install rails
You'll get a few error messages at the end saying you have to add some other bundles...
Just make sure you're in the home ~ directory when you're installing so the permissions won't be an issue, but just in case...
I again ran:
rvm fix-permissions
and:
rvm debug
which told me I had to download yarn, I didn't save the output for it. Basically I did whatever the prompt told me to do if it had to do with my OS.
-D

I don't like to install stuff with sudo.
once you start with sudo you can't stop..
try giving permissions to the Gems directory.
sudo chown -R $(whoami) /Library/Ruby/Gems/2.0.0

sudo chown -R $(whoami):admin /usr/local
That will give permissions back (Homebrew installs ruby there)

Related

Sass is not working & Can't install ruby-sass on macOS Catalina

Ruby sass is not working after upgrading to macOS Catalina beta.
When I run sudo gem install sass, I'm getting an error:
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.11.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20191007-37566-177grvx.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h
You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.11.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.11.1/gem_make.out```
Problem solved, here's the solution
Open terminal & run these code
Step 1: brew update
Step 2: xcode-select --install
Step 3: sudo gem install -n /usr/local/bin sass
Now check your sass version: sass -v
Let me start by pressing people not to install gems with sudo. Since Catalina, user permissions changed for core/system files, which perfectly makes sense. This way no program can change the core files and they are save and secure.
Now the correct way to solve this issue is to install an additional Ruby build in your home folder which can be altered and tempered with.
brew update && brew install rbenv ruby-build
xcode-select --install
vim ~/.zshenv
add the following to the opened file export PATH="$HOME/.rbenv/bin:$PATH"
vim ~/.zshrc
add the following to the opened file:
source $HOME/.zshenv
eval "$(rbenv init - zsh)"
source ~/.zshrc
rbenv install 2.6.4 or any version you feel comfortable with
rbenv global 2.6.4
ruby -v check current running ruby version
ruby -e "puts (1..100).reduce(:+)" outputs 5050
Now install any gem you want gem install sass
Since macOS Catalina has removed ruby from the base install, you are no longer able to execute the sass executable installed via gem.
However, you can install Dart Sass as instructed on the sass website:
Install on Mac OS X (Homebrew)
If you use the Homebrew package manager for Mac OS X, you can install Dart Sass by running
brew install sass/sass/sass
Before doing this however, it may be wise to uninstall the instance of sass that was installed via gem
gem uninstall sass
If you come across any issues with linking the sass that was installed via brew, you may need to manually link it (brew will usually tell you this if it is the case)
brew link --overwrite sass
In my case several Ruby folders and files didn't have permissions to enter directories and read files.
macOS Catalina 10.15.7
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
{{ disable SIP Security }}
$ sudo find /Library/Ruby/ -type d -exec chmod -v o+x {} +
$ sudo chmod -Rv go+r /Library/Ruby/
{{ enable SIP Security }}

Updated to High Sierra and having trouble running compass

I updated to High Sierra earlier this week and am having trouble running compass. When trying to run compass watch it gives me this error:
compass watch
-bash: /usr/local/bin/compass: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
Tried to update ruby and failed. I have version 2.3. I don't have version 2.0 thats its looking for. so tried to change the path, failed again.
Also tried to update/reinstall compass.
I get an error saying I don't have permission to make changes.
I had the same problem. Solved it by running:
$ sudo gem uninstall compass
$ gem update --system
$ sudo gem install compass
Hope it works for you!
UPDATE:
From ewartx: https://github.com/Compass/compass/issues/2129
\curl -sSL https://get.rvm.io | bash -s stable
rvm install 2.0.0
gem install compass
If you don't want to revert, this worked for me (slightly modified from an answer here https://github.com/oklai/koala/issues/679)
Open Terminal
Install Homebrew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Do not close Terminal, open Mac Appstore and check Update, install all XCode Command Line Tools updates OR in my case, XCode Command Line Tools started install automaticly throught Terminal right after step
2.
Back to Terminal
Install Ruby: brew install rbenv ruby-build
At this point, install Compass (instead of SASS in original answer)
Install Compass gem: sudo gem install -n /usr/local/bin compass
I just ran into this as well. The solution was to make sure that the xCode command line tools were installed.
Run the following to install the needed development files.
xcode-select --install
Per #Adi's solution run this to uninstall compass and reinstall it.
sudo gem uninstall compass
gem update --system
sudo gem install compass
After that is complete you should be able to use compass and can re-run your command.

Ruby gems. Unable to add sources

I had this problem "https://stackoverflow.com/questions/19612185/unable-to-install-cocoapods-gem-from-rubygems-org-bad-response-backend-read-e" and as one of the solutions said I tried to remove/add rubygem sources. It was removed without problem, but when I tried to add it back it's giving me an error.
Here's my action on terminal and response:
$ gem sources --add https://rubygems.org/
Error fetching https://rubygems.org/:
server did not return a valid file (https://rubygems.org/specs.4.8.gz)
Does anyone know what is the problem?
Here is Easy Steps for installing Ruby in your system to help to install Cocoapods in your machine, I solved the same issue with being below mentioned steps.
Install command line tools using the command
xcode-select --install
Install Homebrew by
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Ruby using homebrew
brew install ruby
Check Ruby version
ruby -v
Install Ruby
gem source -a http://rubygems.org/
gem install cocoa pods
sudo gem install cocoapods
or
sudo gem install -n /usr/local/bin cocoapods
Go to below folder
cd ~/.cocoapods/repos
Run the below command
git clone https://github.com/CocoaPods/Specs.git master
Go to the directory where Podfile is present and run
pod install
Happy Coding😊
Steps:
1. sudo gem install cocoapods
2. pod install
3. pod update
ensure that you are connected to internet. Your system is unable to find the latest version of gems, required by pods

Compass not working after el capitan install

When i use compass watch it doesn't see any changes on el capitan.
On mavericks it works and detects everything.
Does someone know what is a fix?
I'm no expert on Mac OS, but it looks like the OS wants us to install to /usr/local/bin rather than /user/bin from now on. So I installed compass using:
sudo gem install -n /usr/local/bin compass
I had the same issue. It is due to Apple implementing System Integrity Protection (SIP). You have to first disable that...
Reboot in recovery mode:
Reboot and hold Command + R until you see the apple logo.
Once booted select Utilities > Terminal from top bar.
type: csrutil disable
then type: reboot
Once rebooted
Open terminal back up and enter the commands:
sudo gem uninstall bundler
sudo gem install bundler
sudo gem install compass
sudo gem install sass
sudo gem update --system
The the individual gems that failed need to be fixed, so for each do the following:
On my machine this was the first dependency not working so I listed it:
sudo gem pristine ffi --version 1.9.3
Proceed through the list of gems that need to be repaired. In all you are looking at about 10 minutes to fix it, but you will have terminal commands for compass working.
Screenshot
Tried #jbalesteri answer but doesn't work for me. I updated ruby to version 2.2.3 and now work fine. Below are all the commands I used to update if someone need it as reference.
\curl -L https://get.rvm.io | bash -s stable --ruby
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
sudo chown -R $(whoami):admin /usr/local
brew update
rvm install ruby-2.2.3
rvm use ruby-2.2.3
gem update --system
gem install compass

Installing RVM on existing ruby1.8 installation

I have a big problem with my Debian server configuration. Someone before me has made a big mess with ruby installation and now i can't manage to get it all working. What i'm trying to do now is to get back to environment, where ruby1.8 is installed and rails app is working correctly with apache+passenger. If it would be working on RVM it would be perfect. Here is the story:
There was ruby 1.8 installed on a server. The person has removed it with sudo apt-get remove ruby1.8 and then installed version 2.0.x manually using those commands:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | tar xz
cd ruby-2.0.0-p247
./configure
make
sudo make install
Then, he has removed all the dirs listed by whereis ruby with rm command.
And here i came - i want to install RVM on this server. The problem is, no matter what i do, i get a lot of errors from all sides. Steps i've done:
# Install RVM
curl -L https://get.rvm.io | bash -s stable
# install 1.8.7 version
rvm install 1.8.7
# use 1.8.7
rvm use 1.8.7
# Install gems
bundle install
First thing (and that's just a tip of iceberg) is that i'm not able to start apache2 in cause of the following error:
apache2: Syntax error on line 203 of /etc/apache2/apache2.conf: Syntax
error on line 1 of /etc/apache2/mods-enabled/passenger.load: Cannot
load
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
into server:
/usr/lib/ruby/gems/1.8/gems/passenger-4.0.5/libout/apache2/mod_passenger.so:
cannot open shared object file: No such file or directory Action
'configtest' failed.
Looks like there is even no /usr/lib/ruby/ dir on my system right now.
The question is: is there any way to reset all ruby-releated libraries on debian to the original state (debian without ruby installed) and install working RVM on top of that? Thanks in advance for any help.
Verify if, Is ruby installed correct by ruby -v
Install phusion passenger
$ sudo gem install passenger
$ sudo passenger-install-apache2-module
and then follow onscreen instructions

Resources