What is ruby-build for? - ruby

I'm trying to install jekyll to create my own github page referring to other bloggers. Many of them install rbenv to manage different versions of ruby on mac, but also install ruby-build. No one actually explains what this is for. I'd appreciate if anyone knows about it.

My basic understanding is that rbenv manages the different versions and lets you pick and choose at will. ruby-build is the actual tool that downloads the different versions.
ruby-build docs
ruby-build is a tool that downloads and compiles various versions of
Ruby. It is available as a plugin for rbenv that provides the rbenv install command, or as a standalone program.
rbenv docs
Provide support for specifying application-specific Ruby versions.
Let you change the global Ruby version on a per-user basis.
Allow you to override the Ruby version with an environment variable.

Related

Should I use the pre-installed Ruby on a Mac?

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.

Where does rbenv install ruby?

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.

How to have rbenv include a Ruby version that was not installed thru rbenv

My command had created tool chains for a number of different tool including Ruby; it is an older version (1.9.3) and available from a network drive /company-tool/bin
I like to explore and learn some of the newer features of Ruby, so I installed v2.0.0 and v2.3.0 and I am using rbenv to manage them.
However, for the my company's tools/systems, I will need to use Ruby that is from /company-tool/bin and not from my rbenv.
Is there a way that I can configure/inject this 1.9.3 version of Ruby into rbenv such that I can use rbenv to switch between the locally installed Ruby and to my company's provided Ruby?
Or is there a better approach for this?
rbenv simply looks for Ruby versions in dirname $(rbenv prefix) (usually ~/.rbenv/versions). You can just symlink your Ruby into that directory.

How to upgrade from ruby 2.2.3 to ruby 2.3.0

My current Ruby version is 2.2.3 and I want to upgrade it to 2.3.0.
I use rbenv using this guide: gorails.com/setup/ubuntu/16.04
How do I upgrade my Ruby version? And when I upgrade, does it affect anything that I need to be aware of?
This answer had been written to address the original question, which did not specify rbenv as a preferred approach. Although the question changed after this answer was written, the answer has been retained to help users that may be using RVM to upgrade/manage their Ruby installations.
See the rbenv answer for details on using rbenv for the same purpose.
Use RVM or another Ruby version manager. This is far superior to installing a new system Ruby in most cases.
If you're upgrading your system Ruby, you have a number of things to keep in mind:
what other dependencies are there on that Ruby version?
are all of the gems going to be available after upgrade?
which applications are using the existing Ruby version and what can/will break after upgrade?
are there any other users using the existing Ruby that need to be aware of (and prepare for) the change?
With a Ruby version manager, you eliminate most of these concerns. You can run multiple Ruby versions on the same machine, which gives you the ability to test backward and forward compatibility. It also lets you experiment with the newer Ruby versions to make sure that they're fully stable for use.
You can install RVM using this method from any bash shell:
\curl -sSL https://get.rvm.io | bash -s stable
or update it to the most recent stable version by using:
rvm get stable
Once RVM is installed (or updated), you can install any Ruby version you choose, by doing the following:
rvm install 2.3.0
or upgrade from one version to another:
rvm upgrade 2.2.3 2.3.0
You can see which Ruby versions are installed by using this:
rvm list
You can also check to see which versions of Ruby that you can install on RVM by using this command:
rvm list known
Switch to a specific installed Ruby version by using the use command:
rvm use 2.3.0
and then switch back to an older version when you need to:
rvm use 2.2.3
Check out the RVM documentation for more features. You'll be surprised at how useful RVM actually is. There's a whole lot more to it than just what's shown here.
To upgrade your Ruby version using rbenv, you can use these steps. Some will only be necessary based on your environment. Plugins are an important aspect of this, if you have any installed.
Update rbenbv
First, you'll want to make sure that your rbenv version is updated. If you have the update plugin installed, you can update rbenv and all installed plugins using a single command:
rbenv update
Using the update plugin is highly recommended. However, if you are not using the update plugin, you can manually update rbenv in this way:
cd ~/.rbenv
git pull
Update plugins
If you have manually updated rbenv, you'll also need to update the plugins manually, as well. Make sure to follow the update instructions for each plugin.
One plugin that's very important to update at this point (if you have it installed) is the ruby-build plugin, which provides build support for Ruby under rbenv. This may improve the experience installing a new Ruby version in the next step.
Install Ruby version
After you have updated rbenv, you can install the new Ruby version:
rbenv install -v 2.3.0
Remove Ruby version
rbenv will allow you to manage and use multiple Ruby versions on a single machine. This is a huge benefit. However, if you no longer want the older Ruby version installed, you can remove it like this:
rbenv uninstall 2.2.3
Note that you can always re-install the Ruby version after uninstalling it, and use rbenv to manage the versions separately. This is good practice when working with multiple projects.

How to update Ruby to 1.9.x on Mac?

I have created a new user account on my mac and I am trying to update to the current version of ruby on it (1.9.2) from the snow leopard default of 1.8.7. Can somebody point me to tutorial or explain the best method to update Ruby on my mac from 1.8 to 1.9.2? Thanks
As The Tin Man suggests (above) RVM (Ruby Version Manager) is the Standard for upgrading your Ruby installation on OSX: https://rvm.io
To get started, open a Terminal Window and issue the following command:
\curl -L https://get.rvm.io | bash -s stable --ruby
( you will need to trust the RVM Dev Team that the command is not malicious - if you're a paranoid penguin like me, you can always go read the source: https://github.com/wayneeseguin/rvm ) When it's complete you need to restart the terminal to get the rvm command working.
rvm list known
( shows you the latest available versions of Ruby )
rvm install ruby-2.3.1
For a specific version, followed by
rvm use ruby-2.3.1
or if you just want the latest (current) version:
rvm install current && rvm use current
( installs the current stable release - at time of writing ruby-2.3.1 - please update this wiki when new versions released )
Note on Compiling Ruby: In my case I also had to install Homebrew Link to get the gems I needed (RSpec) which in turn forces you to install Xcode (if you haven't already) https://itunes.apple.com/us/app/xcode/id497799835 AND/OR install the GCC package from: https://github.com/kennethreitz/osx-gcc-installer to avoid errors running "make".
Edit: As of Mavericks you can choose to install only the Xcode command line tools instead of the whole Xcode package, which comes with gcc and lots of other things you might need for building packages. It can be installed by running xcode-select --install and following the on-screen prompt.
Examples: https://rvm.io/workflow/examples/
Screencast: http://screencasts.org/episodes/how-to-use-rvm
Note on erros: if you get the error "RVM is not a function" while trying this command,
visit: How do I change my Ruby version using RVM? for the solution.
I'll make a strong suggestion for rvm.
It's a great way to manage multiple Rubies and gems sets without colliding with the system version.
I'll add that now (4/2/2013), I use rbenv a lot, because my needs are simple. RVM is great, but it's got a lot of capability I never need, so I have it on some machines and rbenv on my desktop and laptop. It's worth checking out both and seeing which works best for your needs.
With brew this is a one-liner:
(assuming that you have tapped homebrew/versions, which can be done by running brew tap homebrew/versions)
brew install ruby193
Worked out of the box for me on OS X 10.8.4. Or if you want 2.0, you just brew install ruby
More generally, brew search ruby shows you the different repos available, and if you want to get really specific you can use brew versions ruby and checkout a specific version instead.
I know it's an older post, but i wanna add some extra informations about that.
Firstly, i think that rvm does great BUT it wasn't updating ruby from my system (MAC OS Yosemite).
What rvmwas doing : installing to another location and setting up the path there to my environment variable ... And i was kinda bored, because i had two ruby now on my system.
So to fix that, i uninstalled the rvm, then used the Homebrew package manager available here and installed ruby throw terminal command by doing brew install ruby.
And then, everything was working perfectly !
The ruby from my system was updated !
Hope it will help for the next adventurers !
I'll disagree with The Tin Man here. I regard rbenv as preferable to RVM. rbenv doesn't interfere drastically with your shell the way RVM does, and it lets you add separate Ruby installations in ordinary folders that you can examine directly. It allows you to compile Ruby yourself. Good outline of the differences here: https://github.com/sstephenson/rbenv/wiki/Why-rbenv%3F
I provide instructions for compiling Ruby 1.9 for rbenv here. Further, more detailed information here. I have used this technique with easy success on Snow Leopard, Lion, and Mountain Lion.
Dan Benjamin's Hivelogic article Installing Ruby, RubyGems, and Rails on Snow Leopard is the recommended place to go although the article is for 1.8, so here's a Ruby 1.9-specific install on Snow Leopard. Watch out for the 64-bit thing... either go all 64-bit 'fat' (as is - for example - Apache on OS X, which can cause problems with 32-bit libraries) or check any gems you're likely to use to make sure they're okay for 64-bit.
This command actually works
\curl -L https://get.rvm.io | bash -s stable --ruby
As previously mentioned, the bundler version may be too high for your version of rails.
I ran into the same problem using Rails 3.0.1 which requires Bundler v1.0.0 - v1.0.22
Check your bundler version using: gem list bundler
If your bundler version is not within the appropriate range, I found this solution to work: rvm #global do gem uninstall bundler
Note: rvm is required for this solution... another case for why you should be using rvm in the first place.
There are several other version managers to consider, see for a few examples and one that's not listed there that I'll be giving a try soon is ch-ruby. I tried rbenv but had too many problems with it. RVM is my mainstay, though it sometimes has the odd problem (hence my wish to try ch-ruby when I get a chance). I wouldn't touch the system Ruby, as other things may rely on it.
I should add I've also compiled my own Ruby several times, and using the Hivelogic article (as Dave Everitt has suggested) is a good idea if you take that route.

Resources