How to manage ruby version installed without rbenv in rbenv? - ruby

I had problems installing ruby with rbenv so I installed it with Homebrew.
The problem is that I still want to manage this ruby version with rbenv.
How can I do that?

Let's say you installed ruby 2.7 (brew does not let you choose patch version): brew install ruby#2.7.
We will call this version 2.7-brew in rbenv but you can call it whatever you like (for example 2.7). Just change all pathes in this answer from 2.7-brew to 2.7 or to another name.
We want rbenv to manage this ruby version:
cd ~/.rbenv/versions
mkdir -p 2.7-brew/bin
We need to link our newly installed ruby version:
replace <Installed Version> with the version brew installed (probably 2.7.7 or a greater patch version)
If you don’t know the version or the installation directory run:
brew info ruby#2.7
Link this ruby version to the directory we have created:
On Mac computers with apple silicon (M1).
ln -s /opt/homebrew/Cellar/ruby#2.7/<Installed Version>/bin/ruby 2.7-brew/bin/ruby
On Mac computers with amd64 architecture (Intell).
ln -s /usr/local/Cellar/ruby#2.7/<Installed Version>/bin/ruby 2.7-brew/bin/ruby
Let rbenv know that we added a new ruby version:
rbenv rehash
Now, rbenv should be able to use this new ruby version.

Related

where is ruby 3.0.0 on rbenv

rbenv install --list-all shows me, among many other things of course,
3.0.0-dev
3.0.0-preview1
3.0.0-preview2
But where is 3.0.0 itself, the actual final release? I'd like to try it out. Not all announced features made it into the previews so I need the real thing.
rbenv install passes thru ruby-build. You need to update (brew upgrade if installed via Homebrew) your ruby-build in order to see the latest versions.
On Ubuntu
Short answer:
# You need to update the available versions via ruby-build
~ git -C ~/.rbenv/plugins/ruby-build pull
~ rbenv install 3.0.0
...
Installed ruby-3.0.0 to ~/.rbenv/versions/3.0.0
Long answer with a beautiful picture🐈: https://richstone.io/where-is-ruby-3-0-0-on-rbenv/
Ubuntu
git -C ~/.rbenv/plugins/ruby-build pull (pulls latest ruby versions)
rbenv install 3.0.0 (or for later versions: 3.x.x)
echo "3.0.0" > .ruby-version OR rbenv local 3.0.0 to ensure ruby 3.0.0 is used.
Mac
brew upgrade

Updating Ruby Mac OS 10.6.8 Snow Leopard

I'm trying to install a more recent version of Ruby on Snow Leopard so I can install Jekyll. When trying to install any version of Jekyll I get an error saying that it requires liquid, which requires ruby v2+.
If I try upgrade via rbenv I get the following when trying all versions:
error: failed to download ruby-2.1.1.tar.bz2
BUILD FAILED (OS X 10.6.8 using ruby-build 20181019)
I've also installed Ruby manually from source but this isn't recognised by the system and I can't switch versions.
If i run rbenv global it only recognises the System version of Ruby.
When I try brew upgrade ruby I get the following error:
ruby 2.5.3_1 already installed
If I try link to the new version with brew I get the following error:
brew link --force --overwrite ruby#2.5.3_1
Error: No such keg: /usr/local/Cellar/ruby#2.5.3_1
RVM doesn't install so I'm not sure what to do next. Below are the details of the packages I have installed.
Xcode 3.2.2 (I cant get an installer working for any higher versions of Xcode). The more recent versions hosted by Apple for Snow Leopard are corrupt when downloaded.
rbenv 1.1.1
brew 1.8.4
ruby 1.8.7 (System)
You have (or had) a path issue. Before you did your follow up steps, if you had run which ruby you'd probably see it pointing to /usr/bin/ruby which is system ruby, not your homebrew ruby in /usr/local/bin/ruby.
You still need to, if you haven't already, add your export command to your ~/.bash_profile file to ensure your PATH gets updated for every terminal window you open.
I'm not sure what actually fixed this but I ran the following commands after reading other posts and now have Jekyll 3.8.3 installed and ruby 2.5.3p105.
sudo chown -R "$USER":admin /usr/local
export PATH=/usr/local/bin:$PATH
brew link --overwrite ruby --force
gem install jekyll

Ruby OpenSSL Install on Mac 10.10 Yosemite

Using brew I go though the normal install process to get rbenv and Ruby installed.
Everything goes smoothly but it is soon apparent Ruby did not install with openssl onboard.
The only thing that seems to allow rbenv to auto install openssl during the ruby install is to use this:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include /usr/include
Is this a bug in rbenv or brew that needs fixing?
There's a long thread about rbenv with openssl on Github here
The easiest way to fix it are:
1) Update to the latest version of rbenv where they fixed the CONFIGURE_OPTS options, then delete and re-build all your ruby versions.
2) Use the older version of rbenv and explictly set the CONFIGURE_OPTS to use the brew openssl:
CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install <whatever version you need>

Force rbenv to install openssl?

I have an existing version of openssl installed, however its the old version. Upgrading to new releases of Ruby, using rbenv, does not upgrade openssl.
How do I force rbenv to upgrade?
This is under ubuntu 10.
rbenv is not a package manager. This is a good thing.
If you want to use a newer version of openssl, simply specify it when you compile ruby
$ ./configure --prefix=$HOME/.rbenv/versions/2.0.0-p247 --with-opt-dir=/usr/local/opt/openssl --enable-shared
To see more help, use $ ./configure --help
If you're using rbenv ruby-build plugin, you can use CONFIGURE_OPTS
$ CONFIGURE_OPTS="--with-opt-dir=/usr/local/opt/openssl" rbenv install 2.0.0-p247
Read more about Special Environment Variables for ruby-build

rbenv not showing the available ruby versions

I have installed rbenv in my vagrant machine but when I try to list all the available ruby versions rbenv versions then it gives me this output:
system (set by /home/vagrant/.rbenv/version)
Does anyone know what is this?
Are you asking what the output of that command means? I'm looking at the rbenv documentation, and I think it indicates that rbenv only knows of one version of ruby - the version that came installed with your system.
Edit: If that's not the answer you were looking for, can you tell us what you expected to see? Did you have other versions installed on that machine?
Edit 2: If you want to see a list of versions you can install onto your machine, but aren't installed yet, run:
rbenv install --list
Here is more documentation for this command. This will help!
If you have tried both rbenv install --list and ruby-build --definitions and still can't see the latest Ruby versions on the list, then you need to upgrade ruby-build because that is what rbenv uses to "know" the available versions.
For example, assuming you use Mac OS X and installed ruby-build using Homebrew, you can update ruby-build by invoking:
brew upgrade ruby-build
Now, try listing the available versions again, and you should see the latest ones there.
Edit:
The ruby-build wiki lists a couple of ways of updating it, namely the above one using Homebrew and another one where it is installed as a plugin to rbenv:
cd "$(rbenv root)"/plugins/ruby-build && git pull
Rbenv is usually installed with it's companion ruby-build
You can get the versions available to be installed with:
ruby-build --definitions
To get a list of available ruby versions you can install, type the following:
rbenv install -l
To get a list of the ruby versions already installed on your machine, type the following:
rbenv versions
To answer your question as to what the below means:
system (set by /home/vagrant/.rbenv/version)
This is telling you that the system ruby (the default ruby installed on your system) is the only ruby version installed on your vagrant machine. Rbenv is using the default system ruby because it doesn't have any other ruby versions installed yet.
To see all available versions:
rbenv install --list-all
Or
rbenv install --list
To list only stable releases for each Ruby implementation.
If you are on Mac
brew upgrade rbenv ruby-build also works.
Documentation
List rbenv versions that are possible to install
"Only latest stable releases for each Ruby implementation are shown.
With the fewest key strokes (shorter than --list and --list-all)
rbenv install -l
Want to see what is available from rbenv to install?
ruby-build --definitions
Want to narrow that down a bit?
ruby-build --definitions | grep 3.0
To upgrade to the latest rbenv and update ruby-build with newly released Ruby versions, upgrade the Homebrew packages:
brew update && brew upgrade rbenv ruby-build
Also you can always just type rbenv
Which will give you a help menu
rbenv
TLDR the manpage or github repo or just plain forgot?
Take a peek at this site for quick rbenv recollection:
https://devhints.io/rbenv
Also, you may need to brew upgrade if you have installed with brew see here.

Resources