Mac terminal problems - ruby

I recently switched over from windows pc to mac for development and i´m looking for some help regarding the terminal.
When i try to install compass wich is a ruby gem, i´m met with this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/1.8 directory.
Is there a way for me to execute gem installments etc without doing sudo?
I found out that this "sudo chown -R $USER /usr/local" worked for npm. Now im looking for a way to do the same with ruby and yeoman.

As the commenters have pointed out, it is recommended that you try to use rvm or its cousins, to install ruby into your home directory, this way, you dont need root to install gems by default, and this is more widely recommended.
Alternatively you could try the same chown trick here
try
sudo chown -R <username>:<username> /Library/Ruby/Gems
The second one is usually group name, it can be skipped, or you can let it stay.

Related

OSX: Permissions issue after installing Ruby Gem or Node modules

I've recently started having an issue installing any Ruby gem or node modules on my local dev environment when it comes to installing anything via the terminal. It was working normally for some time.
sudo gem install compass
This appears to install correctly however when i run
compass -v
I get
/usr/bin/compass: Permission denied
When I browse to /usr/bin/compass and "Get Info" on compass it says system - Read & Write, everyone - No Access as opposed to everyone - read only or...
-rwx------ 1 root wheel 512 Jul 27 14:46 compass
For some reason everything is getting written with incorrect permissions.
Same goes for Node.js modules.
sudo npm install gulp
Appears to work but I get the same permissions issue when I try to use it
/usr/local/bin/gulp: Permission denied
I've exhausted my search and hope someone can help provide some insight on how I can permanently fix this issue
This is happening because you're installing gems with sudo and, as such, root is taking possession of everything. So, instead of using sudo I'd advise using RVM. RVM provides you with an easy way to manage multiple versions of Ruby, each of which gets their own home for gems in ~/.rvm which avoids the permission difficulties you're experiencing. Additionally, it's possible (but not recommended) to do a global RVM install that works for all users.
EDIT: As the Tin Man mentioned in response to me, a global RVM install is not only not recommended in a general sense, but the RVM authors themselves advise against it. Caveat emptor and such. You should find the single-user version more than adequate in any case, though.

Command Not Found Jekyll

I'm trying to create and publish a Jekyll blog using this template.
I installed Jekyll initially. Without any luck, I did resort to installing it via sudo. (And have now since uninstalled it!)
Jekyll(1.4.2, 1.0.3) and am running rvm with ruby 2.0.0p195. After installing the gem, I run jekyll serve in the folder but get the error: Zsh Command Not Found. I tried changing my path to no avail. Any advice on how to troubleshoot?
I cannot uninstall/reinstall nokogiri (see other SO articles on this) because of dependencies related to work projects.
If you're using rvm you should not install gems with sudo. Rvm is user-specific (the binaries are all in your home directory), so putting Ruby stuff in system-wide folders with sudo will not work. Just install without sudo and you should be ok.
The rvm docs tries to explain this a little bit here:
http://rvm.io/rubies/rubygems
DO NOT use sudo...
...to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)

gem issue when using sudo

I have made a script that is already working properly in my development environment with RVM. This script reads *.eml files and parses them.
Now, my problem is this. When I transfer it to the production server, it gives a Permission denied - filename.eml (Errno::EACCES) when reading some files. When I manually read these files using sudo nano filename.eml, it is readable so I thought running my ruby script with sudo is the answer.
But when I tried running it with sudo ruby scriptname.rb, this time it gives me a cannot load such file -- mail (LoadError).
The mail gem is clearly installed and is shown both in gem list --local and sudo gem list --local.
The ruby versions are identical with or without sudo (1.9.3).
The mail gem is also accessible using sudo irb then typing require 'mail'.
Both development and production environments are on a Mac OS with RVM-managed ruby versions.
Any help will be greatly appreciated. Thanks.
maybe the gem is not readable for your server user, such as 'wwwroot', so please make sure the file is 775 mode. e.g.
cd $GEM_HOME
sudo chmod 755 -R .
then everything is readable for other group's users.

What is the correct way to install brews and gems on OS X

It seems every time I want to install something locally on Snow Leopard, I run into an issue about whether to install to /usr/local or whether or not to run install commands using sudo. I've read conflicting advice on this, including on stackoverflow
Gem install errors writable and PATH (use sudo)
gem install permission problem (do not use sudo in comments)
Should I be installing brew formula and gems using sudo? How can I avoid errors and warnings when I install without sudo privileges?
e.g when running gem update:
WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and
/usr/bin aren't both writable.
WARNING: You don't have /Users/luke/.gem/ruby/1.8/bin in your PATH,
gem executables will not run.
I'm not a ruby developer but want to use sass and compass, so it seems like overkill to install rvm. Will just adding ruby to my path resolve all these issues? I also saw somewhere that I should chown /usr/local. It would be good to finally get to the bottom of this.
You're doing yourself a great disservice by dismissing RVM. I don't think it is overkill at all, in the time it would have taken you to write this SO question, RVM would have installed AND you would have also finished installing Ruby (1.8 or 1.9 whichever you prefer). Then your gem warnings and sudo problems would have been non-issues. Pretty much everyone in the ruby community is using RVM these days (unless they are on windows), including, in some cases, in production.
Having said all of that, Homebrew (which you mentioned) has a wiki page that talks about sudo, installing gems to /usr/local, rubygems etc. You could do worse than follow their advice.
I prefer to use sudo, so I am sure that programs running with normal privileges can't mess with system-wide files. I also normally run as a non-administrator user for the same reason. This means that I am protected from damaging the system even accidentally, but when I decide to install something to /usr/local I have to use sudo, so I only do that when I'm sure that it won't make a mess. For stuff that I'm not sure about, or that I simply want to try, etc., I install to a prefix in my home.
Other people have a more single-user mentality, and chown /usr/local to themselves. They're ok with the risk of messing up its contents with normal usage: for instance, if they try to install something to a prefix in their home, but the configure is borked, it could install some pieces in /usr/local without so much as a warning. OTOH, when they install to /usr/local they are sure that they won't affect the rest of the system, only /usr/local and their own home.
But then, /usr/local is just an extension of their home directory, since it has the same ownership and the same privileges. They might as well install to ~/usr/ and add ~/usr/bin to their PATH, which is what I do when I want to install things for myself.
The very best way would probably be to chgrp /usr/local to some special group, and sudo to a special user in that group that can write to that directory, but not do other random sudo stuff. Maybe someday I'll get around to configuring it that way. In the meantime, I prefer to use sudo when I want to install to /usr/local. The advantage of using a package manager like homebrew is that formulas have been checked to ensure that they install cleanly, and they can easily be uninstalled.

RubyGems installation errors both when using 'sudo' and not using sudo

I have a machine that is running Ubuntu Hardy, which provides its own RubyGems package. Unfortunately that version of RubyGems (1.1.1) is too old to do anything useful with, so I decided to manually update RubyGems to the current version (1.3.6). That part went smoothly, and if I do gem -v, I get 1.3.6 which is expected. The problem is when I try to do: sudo gem install rack, it returns this error:
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/username/.gem
Usually when I install gems as root, it knows to install it into /usr/lib/ruby/gems, so why is it checking my home directory at all? Another quirk is when I do gem install rack (not as root), it says:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /usr/lib/ruby/gems/1.8 directory.
which is where I want it to go. I've already tried clearing source_caches, trying different versions of RubyGems (1.3.5), forcing installation into /usr/lib with -i to no avail. Any ideas on why RubyGems is so insistent on checking my /home directory when installing as root?
Sounds like it could be a path issue coupled with having multiple versions installed.
Any difference in output between:
sudo gem env
and
gem env
Try running:
gem environment
and checking the values for the GEM PATH. More info at http://docs.rubygems.org/read/chapter/10#page31
I was running into the same problem myself on Fedora 15, so I ran 'gem install' with the '--backtrace' option to see what was going on.
It turned out it was failing at /usr/lib/ruby/site_ruby/1.8/rubygems/doc_manager.rb:203 where it tried to chdir to the directory it had previously stored (the home directory of the user I was running sudo as)
I didn't extensively debug to see what the underlying cause was, just rather used a quick workaround so I could continue moving forward. The workaround was simply to cd to the root directory, eg cd /, before running the gem install command.
Hope this helps / solves your issue.
Woulda been easier to su (password) then chmod 755 /usr/lib/ruby/gems/1.8

Resources