I installed Ruby 1.9.2 using homebrew, then installed RVM.
I want to point RVM to the version I have in my Cellar folder. How can I make rvm --default 1.9.1 point to the one in Cellar without having to reinstall it again using RVM?
You can't do it and get the right behavior.
RVM works within its own directory when running as a single-user's sandbox. Any Ruby it controls will exist in your ~/.rvm directory.
Anything outside of RVM's control will be considered the system setting, and it will be up to you to manage whether that is the regular Ruby installed in /usr/bin or /usr/local/bin or in /opt or wherever.
In my opinion, you should let RVM manage the Ruby installations. It is very slick and has rapidly become the favored way to manage Ruby development environments on Linux and Mac OS.
You could try creating aliases from the Cellar folder to the appropriate place in the ~/.rvm, but RVM modifies some things during its install process, such as gem, which would not be done in the Homebrew-installed folder, and would cause RVM's gem support to break for that Ruby version.
Related
I recently installed a version of Ruby (and RubyGems) via homebrew on my Mac because the RubyGems that comes installed on Mac doesn't let you install gems due to permissions issues. I followed the instructions in the top answer in this thread: You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user)
After installing some gems, I realized that I don't need this version of Ruby and RubyGems anymore, so I ran brew uninstall ruby to get rid of them (I assume RubyGems gets deleted along with Ruby). However, I checked and it appears the gems I had installed are still in /usr/local/lib/ruby/gems/2.7.0. Can I just delete the usr/local/lib/ruby folder, and is this the correct way of going about it? I don't know if the default RubyGems that comes with MacOS uses this folder.
Basically when you run rbenv versions it will display all your ruby versions including the one installed by default (system).
system ruby usually located in /usr/local/lib/ruby/gems/2.5.1
rbenv ruby default location is inside user path ~/.rbenv/versions/2.5.1/gems
to uninstall ruby using rbenv you need to remove the specific version e.g rbenv uninstall 2.5.1
I suggest that you leave your ruby system installation, but you can remove all the gems inside the ruby system path manually /usr/local/lib/ruby/gems/2.5.1.
I'm the author of that top post in the link you mentioned. You are correct that Homebrew installs gems in /usr/local/lib/ruby/gems/2.7.0. You can confirm that in two ways:
You can run brew info ruby, and then visit the Formula page that's displayed: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ruby.rb
This is the line of code where the Rubygems directory is defined: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/ruby.rb#L48
You can install Ruby again with Homebrew, and you should see this section in the terminal output:
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/2.7.0/bin
You may want to add this to your PATH.
I wrote about this in the Homebrew section of my definitive guide to installing Ruby gems on a Mac.
The system Ruby is NOT installed in /usr/local/lib/ruby. It is in /Library/Ruby/Gems/2.6.0. You can safely remove the /usr/local/lib/ruby directory. On a fresh macOS installation, the /usr/local directory is empty.
You can then check if Homebrew is still healthy by running brew doctor.
/usr/local/lib/ruby/gems/2.7.0 used to be brew default install path. Now they have changed it to /opt/homebrew/lib/ruby/gems/2.7.0. So you can delete the previous folder under /usr without a problem.
I'm having trouble running a gem on system ruby -- I've done the install, and the gem runs when rvm runs 1.9.2, but doesn't run on rvm system, though that too is 1.9.2. The OS is OSX 10.6.8.
One importance difference seems to be GEM_HOME, as seen in rvm info. This is set for rvm 1.9.2, to values in ~/.gemrc, but not set for rvm system.
So at a guess, the system ruby isn't reading the .gemrc file.
Is there anyway to verify this?
How can I correct it?
The system ruby was installed from source.
The gem in question is compass, version 0.12.1. An install of 0.11.5 also failed.
Also, gem -v is 1.5.3. That's a rollback, I was using 1.8.24 but that too failed and I rolled back to a prior to see if that helped.
The system Ruby doesn't know about any gems you've installed in RVM managed Rubies, nor will it care about a .gemrc file.
The system Ruby stands alone, and for most purposes should be left as it was installed by Apple unless you reeeeeeally know why it's there and what it affects. Apple had their own reasons for installing Ruby and at least one app installed by Apple by default on a Mac OS machine requires it. We're free to use it, but deleting it will break that app, and updating it could cause problems that possibly won't surface immediately, so I think it's best to just ignore it.
If I need a system-wide Ruby for a Mac, I'd install it from source into /usr/local/bin, which is the appropriate place for a replacement. For my own development, I use RVM or rbenv, and let them install in my home directory, which is their default. That way I'm free to mess around to my heart's content, and even blow them away, without any chance of affecting the system.
By the way, the version of Ruby isn't important, it's what installed it and where it's installed.
I've been using the default system ruby version 1.8.7 without RVM for a few rails projects and have not run into any problems. I just recently installed RVM, and after running rvm requirements I get this output:
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 357: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.8.7
I believe what these commands do are to install the same gems that have already been installed using the system ruby under the RVM installed ruby.
My questions are, am I right in what these commands do? and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The one thing that springs to mind is, if you use the system Ruby, you'll use it slightly differently that RVM's Rubies--for example, you'll likely need to use sudo to install gems. Furthermore, you won't be able to use many of RVM's features, like gemsets, with the system Ruby.
Well one reason I can think of is that you don't wanna worry about your system not working even if the system ruby gets updated.
My questions are, am I right in what these commands do?
You are right in what they do. The first command installs Ruby 1.8.7, the second command installs all the gems currently install on your system Ruby installation in the new RVM Ruby 1.8.7 installation, and the third command sets your default version of Ruby to be the RVM Ruby 1.8.7.
and if I am right, why is it important to do this, because if I wanted to use an RVM installed Ruby of a different version like 1.9.2, wouldn't it already separate gems in that version from the system's ruby?
The second command is actually more of about convenience than necessity. Yes, the gems install in the RVM 1.8.7 will be completely separate from the ones installed in the system version of Ruby; however, if you didn't run the second command, you're RVM 1.8.7 would start out with almost no gems (only the defaults). That means that you would need to go through and manually install the gems that you need to get your project up and running. Instead of doing that, the second command allows you to just install the same gems you've already installed in the system version of Ruby to the RVM 1.8.7 version—it doesn't migrate them, it just makes a copy of them. After the second command, there are two distinct sets of the exact same gems: one in the system Ruby and one in the RVM 1.8.7 Ruby. So, if you were to update gems in either of the Rubies, they would get updated, but the other version's gems would be unaffected.
Hope this helps answer your question.
I've done some searching online and tried a few things with no luck.
I compiled Ruby 1.9.1 on a Mac that had previously been running 1.8.7.
How can I now either reinstall the gems, or point. Rubygems installs to the old location, but 1.9.1 is looking elsewhere. I've tried making a 1.9.1 (and 1.9) gems directory as a symlink to the old directory, but that doesn't seem to work. I've tried setting GEM_HOME and GEM_PATH but again no luck.
How can I find out where the current version of ruby is searching for gems at runtime, and alter it? And/or, how can I instruct rubygems to install gems where the latest version is looking for the gems.
You should either use a rvm, as was suggested, or install ruby 1.9.2 to /opt/ruby (configure --prefix=/opt/ruby --enable-shared) or /usr/local or /usr/local/ruby. Then put this path first in your PATH, before everything else. You'll have to reinstall gems anyway, as some of them are incompatible (built for 1.8.7).
It would be a good idea to install rvm and let it wrangle your Ruby versions and gems for you.
Also, you should probably upgrade to 1.9.2, as it's much more stable. 1.9.1 is basically a buggy development version of 1.9.2.
I have installed Ruby 1.9.2 from source. But it seems there is some trouble recognizing the bundler gem which I have already installed.
My /etc/environment file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ruby/bin"
It looks like my gems are in /usr/local/ruby/gems/1.9.1/gems/.
In my rails application when I attempt to run sudo bundle install I get an error:
sudo: bundle: command not found
Also, why do the directories say 1.9.1?
Type which ruby to see the path your system thinks ruby is in.
Did you use a --prefix=... option for configure when you set up the configuration? Normally Ruby from source wouldn't be in /usr/local/ruby/bin. The Ruby executable would be in /usr/local/bin/ruby, but that is not how you'd set up your PATH to use it, so that looks suspicious. Notice that your path already contains /usr/local/bin so if Ruby installed into the normal location for a source-installation, that path will pick it up and your final search of /usr/local/bin/ruby will be wrong and unnecessary.
If you installed the gem before you installed the new version of Ruby then the gem would be part of the previous installation, not the current one, and wouldn't be visible to it. They're separate installs.
Unless you are trying to do a system-wide install for multiple users there is no real reason to compile from source and allow it to install to /usr/local/bin. I highly recommend installing RVM, then letting it install any Ruby versions into RVM's ~/.rvm sandbox. Gems will also be installed relative to the currently enabled RVM controlled ruby, which is a really good thing.