2

I have scoured the internet for answers. I feel I have not followed the right way to do things and just want to set up my rvm environment in the proper way. This all stemmed from me having to use sudo gem install sass to install SASS which I didn't want to do.

Now when I do gem install sass I get:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

Steps I took:

sudo chown -R dhruv: /Library/Ruby/Gems/2.0.0
\curl -sSL https://get.rvm.io | bash -s stable --ruby
brew install gnupg gnupg2
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
sudo chown -R dhruv:staff ~/.rvm
sudo chown -R dhruv:staff ~/.gem
sudo chown -R dhruv:staff /Library/Ruby/Gems/2.0.0

Note that which rvm doesn't return anything, even though running the curl command above gave me:

Upgrading the RVM installation in /Users/dhruv/.rvm/
    RVM PATH line found in /Users/dhruv/.mkshrc /Users/dhruv/.profile /Users/dhruv/.bashrc /Users/dhruv/.zshrc.
    RVM sourcing line found in /Users/dhruv/.profile /Users/dhruv/.bash_profile /Users/dhruv/.zlogin.
Upgrade of RVM in /Users/dhruv/.rvm/ is complete.

# dhruvghulati,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

I want to get things to a state where I can install gems easily without sudo. How do I do this?

Also, how do I prevent these PATH errors I am seeing for rvm?

Also I am worried about when I did sudo chown -R dhruv:staff /Library/Ruby/Gems/2.0.0, the internet seems to say this is a terrible evil and I will have to revert back? Can I revert this to maybe chmod to the original user this should be owned by?


Here is the output of rvm info:

Warning! PATH is not properly set up, '/Users/dhruv/.rvm/gems/ruby-2.2.1/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.2.1'.

ruby-2.2.1:

  system:
    uname:       "Darwin Dhruvs-MacBook-Pro-2.local 14.5.0 Darwin Kernel Version 14.5.0: Tue Sep  1 21:23:09 PDT 2015; root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.10/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)"
    zsh:         "/bin/zsh => zsh 5.0.5 (x86_64-apple-darwin14.0)"

  rvm:
    version:      "rvm 1.26.11 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "1 day 8 minutes 30 seconds ago"
    path:         "/Users/dhruv/.rvm"

  ruby:
    interpreter:  "ruby"
    version:      "2.2.1p85"
    date:         "2015-02-26"
    platform:     "x86_64-darwin14"
    patchlevel:   "2015-02-26 revision 49769"
    full_version: "ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]"

  homes:
    gem:          "/Users/dhruv/.rvm/gems/ruby-2.2.1"
    ruby:         "/Users/dhruv/.rvm/rubies/ruby-2.2.1"

  binaries:
    ruby:         "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/ruby"
    irb:          "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/irb"
    gem:          "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/gem"
    rake:         "/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin/rake"

  environment:
    PATH:         "/Users/dhruv/anaconda/bin:/Users/dhruv/anaconda/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin:/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib"
    GEM_HOME:     "/Users/dhruv/.rvm/gems/ruby-2.2.1"
    GEM_PATH:     "/Users/dhruv/.rvm/gems/ruby-2.2.1:/Users/dhruv/.rvm/gems/ruby-2.2.1@global"
    MY_RUBY_HOME: "/Users/dhruv/.rvm/rubies/ruby-2.2.1"
    IRBRC:        "/Users/dhruv/.rvm/rubies/ruby-2.2.1/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

The command gem install --user-install sass gives me:

WARNING:  You don't have /Users/dhruv/.gem/ruby/2.2.0/bin in your PATH,
      gem executables will not run.
Successfully installed sass-3.4.21
Parsing documentation for sass-3.4.21
Done installing documentation for sass after 4 seconds
1 gem installed

.bash_profile:

export PATH=$PATH:~/.gem/ruby/2.0.0/bin
export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M  -Duser.timezone=GMT"
export PATH=$PATH:~/scripts
source ~/.profile
source ~/.bashrc
export PATH=$PATH:/usr/local/lib
# added by Anaconda3 2.3.0 installer
export PATH="/Users/dhruv/anaconda/bin:$PATH"
export MONGO_PATH=/usr/local

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

.bashrc:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

.profile:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51
  • 1
    Possible duplicate of [How to install RVM system requirements without giving sudo access for RVM user](http://stackoverflow.com/questions/16563115/how-to-install-rvm-system-requirements-without-giving-sudo-access-for-rvm-user) – Mohammad Mar 06 '16 at 18:08
  • Why? That question is about installing via `rvm`, not `gem install`, and that is on Debian. – Dhruv Ghulati Mar 06 '16 at 19:30
  • How did you install RVM? [Installed per the authors' recommendation](https://rvm.io/rvm/install), which is for a single-user, it will do just as you're asking, you won't have to use `sudo`. If you didn't follow the instructions on that page then you should have as they know best. Failing to follow those instructions is probably the cause for the majority of RVM questions on SO. Changing the ownership of `/Library/Ruby...` wasn't good. Apple installs the default Ruby for their own use. You can piggyback on it but don't change it. – the Tin Man Mar 06 '16 at 19:38
  • I installed exactly per those instructions actually, using the `\curl -sSL https://get.rvm.io | bash -s stable --ruby` option and before that `brew install gnupg, gnupg2` to get the gpg command so I could run `gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3` – Dhruv Ghulati Mar 06 '16 at 20:41
  • Then, if you followed the directions exactly, RVM is ready to go and won't require that you jump through any hoops. If you're having to do anything beyond that I'd suggest rereading that page very closely. I have RVM running on multiple machines and it works very cleanly and without any changes to permissions or the use of `sudo`. RVM doesn't manage the default installation of Ruby on Mac OS or other OSes, only Rubies it was used to install them. It sounds like you didn't restart your shell session or didn't let it modify the ~/.bash_profile. – the Tin Man Mar 06 '16 at 21:18
  • @theTinMan please see the comment on the below answer - these are the errors I get. I have restarted shell and already done `source` on the bash files but still get the errors. – Dhruv Ghulati Mar 07 '16 at 12:08
  • Instead of putting required information in comments, reedit your question, putting the additional information into your question as if it'd been added there initially. That way we don't have to read every comment to every answer to try to piece together the information necessary to help you. Please read "[ask]" including the links at the bottom. You have to help us help you. Append the output of `rvm info` to your question, formatted appropriately for readability. – the Tin Man Mar 07 '16 at 16:17
  • Done. Thanks for being clear @theTinMan – Dhruv Ghulati Mar 07 '16 at 19:35

2 Answers2

2

First, stop using --user-install. You shouldn't need it with RVM as that's one of its primary purposes, keeping the gems and Ruby in your home directory.

Your path is not well constructed:

"/Users/dhruv/anaconda/bin:/Users/dhruv/anaconda/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1/bin:/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin:/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib:/Users/dhruv/.gem/ruby/2.0.0/bin:/Users/dhruv/scripts:/Users/dhruv/.rvm/bin:/Users/dhruv/.rvm/bin:/usr/local/lib"

Which breaks down to:

/Users/dhruv/anaconda/bin
/Users/dhruv/anaconda/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib
/Users/dhruv/.gem/ruby/2.0.0/bin
/Users/dhruv/scripts
/Users/dhruv/.rvm/bin
/Users/dhruv/.rvm/bin
/usr/local/lib

You need to have RVM first in the path but you're getting in its way.

It should look something like:

/Users/dhruv/.rvm/gems/ruby-2.2.1/bin
/Users/dhruv/.rvm/gems/ruby-2.2.1@global/bin
/Users/dhruv/.rvm/rubies/ruby-2.2.1/bin
/Users/dhruv/scripts
/Users/dhruv/anaconda/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin

I'd rewrite ~/.bash_profile to:

source ~/.bashrc

export MONGO_PATH=/usr/local
export SBT_OPTS="-Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=2G -Xss2M  -Duser.timezone=GMT"

export PATH=~/scripts:~/anaconda/bin:$PATH

# RVM needs to initialize last so it can adjust the path correctly...
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

I'd rewrite ~/.bashrc to:

# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

I'd rewrite ~/.profile to:

# export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
# [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

That should clean up your path, and probably will allow RVM to figure things out better.

You might need to do minor tweaks but keep it simple.

I'd recommend reading about how the shell uses PATH to find things and how to define PATH. Also, it'd be good to read about using ~/.bashrc, ~/.profile and ~/.bash_profile, especially on Mac OS. man bash at the command-line says, among other things:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

[...]

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

When you install RVM using their default installation, it will create the ~/.rvm directory with the correct permissions. You won't have to do a thing after that to have RVM and Ruby store gems in that directory. Scripts will be able to find gems you've installed without you doing anything special with gem install. If it gets weird or hard something is wrong.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • This is an amazing answer and solves `rvm gemdir` which is now not getting confused and outputs `/Users/dhruv/.rvm/gems/ruby-2.2.1`! You seem to know also the correct order of the PATH and how things should be loaded. It's amazing to me how that long PATH is generated with just `export PATH=~/scripts:~/anaconda/bin:$PATH`, even the `/Library/TeX/texbin` part. No idea how it figures that out without even adding that folder extension to an `EXPORT PATH` command! – Dhruv Ghulati Mar 07 '16 at 20:50
  • 1
    Heh. I'm glad it helped. Programming doesn't involve just writing code, it also involves understanding (and doing) system and user administration, understanding networking including various protocols, plus how computers work, from the CPU on up. Those HR people who think we're "just programmers" haven't got a clue. – the Tin Man Mar 07 '16 at 22:12
0

You can install in your local user directory using this command:

gem install --user-install <gemname>

Alias gem install to gem install --user-install to avoid having to type that in the future.

Also, try running rvm gemdir to find where gems will be installed.

If nothing else, try running rvm reinstall.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Stephen Grimes
  • 398
  • 1
  • 7
  • I did this and then got `WARNING: You don't have /Users/dhruv/.gem/ruby/2.2.0/bin in your PATH, gem executables will not run.` – Dhruv Ghulati Mar 06 '16 at 19:22
  • Also `rvm gemdir` led to `Warning! PATH is not properly set up, '/Users/dhruv/.rvm/gems/ruby-2.2.1/bin' is not at first place, usually this is caused by shell initialization files - check them for 'PATH=...' entries, it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles', to fix temporarily in this shell session run: 'rvm use ruby-2.2.1'. /Users/dhruv/.rvm/gems/ruby-2.2.1`. – Dhruv Ghulati Mar 06 '16 at 19:23
  • Using http://stackoverflow.com/questions/18276701/getting-warning-path-is-not-properly-set-up-when-doing-rvm-use-2-0-0-defaul, I changed my `.bashrc` and `.bash_profile`. The latter has `export PATH=$PATH:~/.gem/ruby/2.0.0/bin source ~/.profile source ~/.bashrc [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*` – Dhruv Ghulati Mar 06 '16 at 19:25
  • The former has `export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"` – Dhruv Ghulati Mar 06 '16 at 19:26
  • A correctly installed RVM won't need any workarounds like these. It'll just work. – the Tin Man Mar 06 '16 at 19:40