I migrated a project a couple of days ago from Fedora to Mac OS. The project uses bundle to install the required ruby gems, and I ran
bundle install when I migrated the project, so today I expected it to just work. But it did not.
One of the gems the project uses is sass, and it also uses a watch task in grunt to compile sass files automatically, However, when I edited a file, I got an error. Sass was not installed. I ran
bundle install again, and noticed that the command was returning some errors about certain files not being writable. This is because of the ‘rootless‘ feature in Mac OS, which prevents anybody, even root, from writing to certain locations. One of those locations is
/usr/bin, which bundle was trying to write to to add the gem executable files. No wonder I was getting a not-istalled error for sass. However, I hadn’t really realize that just jet.
I decided to investigate the issue, and found that some people who had the same problem fixed it by adding certain location to their path. This is when I actually understood what was going on, because even though I had seen the bundle errors, I hand’t really understood the issue. As I said before, bundle was trying to write to a location where it could not. I.e.
I did some more researching and found some information about the gemrc file, and how it can be used to tell
gem where it should install gems. I created a gemrc file, and tried bundle install. The error didn’t get fixed.
I decided to look for the documentation for
bundle install, and there I found that you can specify where gems should be placed, and where the executable files should be placed. I finally ran the command
bundle install --force --path=~/ --binstubs=~/bin
It failed with error
Errno::EACCES: Permission denied @ rb_sysopen – /Users/me/bin/bundle
An error occurred while installing bundler (2.0.0), and Bundler
AT this point I was loosing hope, and getting frustrated, but I continued looking for an answer. That is how I found that I probably had the wrong permissions for bundle. I listed the contents of my
~/bin directory, and found that the bundle file was owned by root. I changed ownership of the file to me, and this finally got everything working correctly.
It may seem like I fixed this issue in no time, but the reality is that I spent over two hours trying until finally being able to make it work. I should say, though, that I am no ruby developer. This project is the only place were I’ve ever used bundle, and gems that I can think of. Plus, I’m finding out that the ‘rootless‘ feature is at a minimum as annoying as selinux, but I would never, ever, advice anybody to disable it, nor would I do it in my own computer: