I'm working on a project that i have to use ruby 1.8.7. I'm using today, ruby 1.8.6 + Mac OSX Darwin. This ruby 1.8.6 was installed with the OS, it's a developer package from Apple. My question is: how can i update this package? if i run ports, it dont find my current installed package and install a new ruby version, with different paths and as effect it breaks my rubygems (i know how to fix it, but it is always workarounds over workarounds).
There is a clean way to update the default ruby that comes with the OS or its better to remove it and just manage it by Port? Please answer like this one How to update to Ruby 1.8.7 don't helps me
Have you tried rvm gem? It manages Ruby versions installed, allow to compile most (if not all) actual (and archival) Ruby versions, sets proper environment variables pointing to actually used ruby version.
$ gem install rvm
$ rvm install 1.8.7
$ rvm use 1.8.7 --default
On my OS X machines I have several versions of Ruby installed.
I install then, from source, under /usr/local/ruby-1.X.X
Once you have multiple versions of Ruby installed you will need your environment to know which one to use.
I do this by setting the PATH, like so
export PATH="/usr/local/ruby-1.8.7/bin:$PATH";
See Hive Logic's article on installing Ruby
Related
I am using macOS Big Sur. When I check if Ruby is available, I see:
$ ruby -v
ruby 2.6.3p62
Checking with which:
$ which ruby
/usr/bin/ruby
I can see Ruby is pre-installed on macOS. But I've been told, "Do not use the system Ruby." Why?
Don't use the system Ruby!
Here are reasons not to use it for developing with Ruby:
the default location for gems is the system Ruby directory /Library/Ruby/Gems/2.6.0 so you will need to be superuser to install gems (and you really shouldn't alter this folder)
you could use sudo to install gems but that's a security risk (gem installation can run malicious code)
using Bundler is a best practice to manage gem versions and dependencies (projects might use different gem versions; or a project might use different gems that need different versions of a common dependency)
you could install Bundler with the --user-install argument to set the gem directory but that's not a common practice
it's best to start projects with the newest version of Ruby and the system Ruby is 2.6.3
if you've got multiple projects and can't update them all at once, you'll need multiple Ruby versions and a version manager (see my guide Install Ruby on a Mac that compares version managers and shows how to install Ruby with asdf or chruby or Homebrew)
the pre-installed Ruby is deprecated by Apple and may disappear in future macOS releases
Some developers use the system Ruby for running sysadmin scripts. That's fine, as long as you don't alter the system Ruby by attempting to update or adding gems. Remember, the system Ruby is there for macOS, not for you. For development, install Ruby with Homebrew or a version manager.
I installed ruby 2.7.1 using rbenv.
How can I find where on Mac OS that version of ruby is located?
Note: I need its location for updating the PATH
Also note: which ruby returns /usr/bin/ruby (the old version)
Rbenv by itself does not install Ruby implementations at all. You simply give it the path to an already installed Ruby implementation.
There are several projects that make installing Ruby implementations easier. One of those is the ruby-build project, which also provides an optional plugin for Rbenv that provides an rbenv install subcommand. This plugin will typically install Ruby implementations in ~/.rbenv/versions/*, but that is configurable.
Note, however, that it is generally not required that you set up the $PATH yourself. rbenv init can do that for you, and it knows the correct path anyway, so you don't have to think about it.
I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0
The `rails' command exists in these Ruby versions:
1.9.3-p327
Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?
As seen here:
You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:
rbenv whence bundle
See your current version:
rbenv version
Install bundler for that version, if missing:
gem install bundler
Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.
If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.
Another solution to this is to copy (or reinstall) the gems from your previous version to the newly installed version. How to do that is answered in detail in this question, which has two scripts -- one to install from local cache, one to reinstall from the internet (mine).
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.
Ok guys, so I've been trying to install ruby on my mac for the past two days. What seems to be happening is that there's a conflict between the stock ruby, rubygems and rails from Mac OS X Snow Leopard and the ones I'm trying to install.
I'm using rvm to get the files, therefore I'm running rvm install 1.9.2. Installation seems to go normally, but when I run ruby -v, it shows me the old version (1.8.7). Same goes for rubygems. While rvm should installs it, when I run gem -v, old version is shown (1.3.5). \
This screenshot shows what I'm saying: http://cl.ly/2a3m1v0u331i272z2J22
Thank you.
Once you've installed RVM, you also need to tell you system that you want to use that version of Ruby. This is usually done via:
rvm use 1.9.2
However, when you open a new shell, it will revert back to the system default. If you want to set 1.9.2 as your default ruby, use:
rvm --default use 1.9.2
I suggest you look through the documentation a bit more to help you get the most out of RVM:
Basics: https://rvm.beginrescueend.com/rvm/basics/
Best Practices: https://rvm.beginrescueend.com/rvm/best-practices/
Check your PATH variable.
echo $PATH
/usr/local/bin should be before /usr/bin.
If not so - change it in your /Users/Your_name/.bash_profile