Switching Ruby versions using homebrew - ruby

One of the projects that I've been working has a dependency on ruby#2.3.
I'm using a Mac and the version of Ruby that I used for other projects is the 2.5.
I want to temporarily switch from 2.5 to 2.3 using brew. I don't want to use neither rbenv nor rvm.
1. I've installed the 2.3.7 version, using brew:
bf-old> brew install ruby#2.3
Warning: ruby#2.3 2.3.7 is already installed and up-to-date
To reinstall 2.3.7, run `brew reinstall ruby#2.3
2. I'm trying to switch to it, but it's not working:
bf-old> brew switch 2.3.7
Error: 2.3.7 not found in the Cellar.
What can I do about this?

Check if both the ruby versions are installed.
If both are installed, then try this:
brew unlink ruby#2.5 && brew link --force --overwrite ruby#2.3

Related

Need help installing Ruby 2.7.2 on Mac

I'm trying to install Ruby version 2.7.2 on my Mac (latest OS with all updates) and did the following
brew update
brew upgrade rbenv ruby-build
and then
rbenv install 2.7.2
ruby-build: definition not found: 2.7.2
See all available versions with `rbenv install --list'.
If the version you need is missing, try upgrading ruby-build:
brew update && brew upgrade ruby-build
So I tried following the instructions above and get this
brew update && brew upgrade ruby-build
Already up-to-date.
Warning: ruby-build 20200926 already installed
You need to install the latest ruby-build
$ brew unlink ruby-build # remove STABLE version
$ brew install --HEAD ruby-build
$ rbenv install -l | grep '2.7.2'
2.7.2
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.
The answer from #andrei-kovrov is correct but, alternatively, you can wait until this PR gets merged:
https://github.com/Homebrew/homebrew-core/pull/62096
Btw, this answer will not age well so, for reference, this is where the formulae are staged before they get released:
https://github.com/Homebrew/homebrew-core/pulls
It might be an issue reading the correct version of ruby based on the path that is specified. If you already have another version of ruby installed the path might not be updated to look for a newer version.
This article has a lot of really great information on how to set up ruby on a mac:
https://stackify.com/install-ruby-on-your-mac-everything-you-need-to-get-going/

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

brew install hadoop installing 2.8.1 version. But needed 2.7.4 version

I have Homebrew 1.3.1
I want to install hadoop 2.7 but brew is installing hadoop 2.8 version.
I tried
brew versions, which is not available anymore.
brew tap homebrew/version, which is now deprecated.
In previous brew version, we were able to use brew tap homebrew/boneyard and then brew versions work. But, now even from homebrew/boneyard the versions command is removed.
Would we good to know the direct command for homebrew to run and install hadoop 2.7.4
(#bfontaine its not a duplicate question as that answer is 6 years ago and no longer works)
You can try running
brew list --versions hadoop
to see if you have previous versions and you can switch to it by running
brew switch hadoop 2.7.4
There is
brew install <package_name>#<version>
Unfortunately it seems hadoop and many other packages haven't set it up to be possible to download the older version and I haven't found out a way to do it.
As I am writing this, there is a version 2.7.7 of hadoop here: https://dist.apache.org/repos/dist/release/hadoop/common/
You can use 'brew edit hadoop' to refer to that version directly, and then run 'brew install hadoop'.

Upgraded rbenv and still can't install ruby 2.4.0

I am trying to install ruby 2.4.0 using rbenv.
I am using homebrew.
When I tried the following command:
rbenv install ruby 2.4.0
I get the following:
ruby-build: definition not found: 2.4.0
The following versions contain `2.4.0' in the name:
2.4.0-dev
2.4.0-preview1
rbx-2.4.0
See all available versions with `rbenv install --list'.
If the version you need is missing, try upgrading ruby-build:
brew update && brew upgrade ruby-build
I performed the brew update and brew upgrade ruby-build commands and I still get the same message that ruby-build definition 2.4.0 not found.
How can I install ruby 2.4.0 and fix this problem?
I found that I had to do the following:
brew reinstall ruby-build --HEAD
then I was able to install ruby 2.4.0 using:
rbenv install 2.4.0
I'm guessing that brew upgrade ruby-build --HEAD did not update the latest ruby installations available.
Start by checking Ruby's version through:
ruby -v
If it's not the version you need, make sure you download it from their Official Website.
Then, if you already have Homebrew installed, you can try the following command:
brew install ruby
Otherwise, you can install Homebrew first through this command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

OpenSSL error installing ruby 2.0.0-p195 on Mac with rbenv

I'm trying to install Ruby 2.0.0-p195 using rbenv on a Mac (Mountain Lion) and got this error.
BUILD FAILED
Inspect or clean up the working tree at /var/folders/vt/27n8h2yj27v7rzq58075f3_m0000gn/T/ruby-build.20130618163859.1669
Results logged to /var/folders/vt/27n8h2yj27v7rzq58075f3_m0000gn/T/ruby-build.20130618163859.1669.log
Last 10 log lines:
installing default gems: /Users/me/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?
When I ran brew install openssl it said
Warning: openssl-1.0.1e already installed
Following a solution on this thread https://github.com/sstephenson/ruby-build/issues/305 I tried to install latest stable this way and got the same error
env CFLAGS='-g -O2' RUBY_CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline`" rbenv install 2.0.0-p195
Any ideas?
Try adding OpenSSL to the config options using the --with-openssl-dir option:
$ CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p195
If you're using Homebrew, you'll need to install OpenSSL before running the above by running:
$ brew install openssl
UPDATE (see #JarkkoLaine 's comment below):
Just for the record, you should not need to use the config opts
anymore with ruby-build and homebrew. However, I had to reinstall
openssl with homebrew to make it work: brew uninstall openssl; brew
upgrade; brew install openssl; rbenv install 2.0.0-p247. See this for
more info.
I fixed this by executing:
brew link openssl --force
Mac OSX 10.9.4
Upgrading to the latest version of ruby-build fixed the problem for me:
Like the OP, I got
BUILD FAILED
Inspect or clean up the working tree at /Users/me/.rbenv/sources/2.0.0-p247
Results logged to /var/folders/3x/y_8y8vr53ws_kxj97km79q5h0000gn/T/ruby-build.20130704172404.3106.log
Last 10 log lines:
installing default gems: /Users/me/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
The Ruby openssl extension was not compiled. Missing the OpenSSL lib?
but installing the latest version of ruby-build, via
# Don't forget brew doctor and brew update if required
brew upgrade ruby-build
fixed it.
Ruby-build had some changes between when the OP asked and now, which would explain why it worked for me, but not for the OP using the latest stable version of ruby-build.
For those who have problems installing openssl.
I had this error on my Mac 10.8.4
brew install openssl
created directory `/usr/local/Cellar/openssl/1.0.1e/include/openssl'
make: *** [install_sw] Error 13
READ THIS: https://github.com/mxcl/homebrew/wiki/troubleshooting
These open issues may also help:
https://github.com/mxcl/homebrew/pull/19429
Create a directory if it does not exist
sudo mkdir /usr/local/etc/openssl
Change the rights. Replace and with your name and group (e.g. serge:admin)
sudo chown -R <username>:<group> /usr/local/etc/openssl/
Repeat openssl installation
brew install openssl
Install curl-ca-bundle
brew install curl-ca-bundle
install ruby
CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 2.0.0-p195
Bingo
Solution using ruby-install:
After uninstalling and installing openssl a couple of times (probably unnecessary) I successfully tried this:
ruby-install ruby 2.1.3 -- --with-openssl-dir=`brew --prefix openssl`
The missing library is libssl*-dev* / openssl*-dev*, depending your distribution.
This issue came up again for me with Mac OS 10.9.5
Mac upgraded the command-line tools and that upgraded openssl, which broken rbenv.
I tried all of these solutions, but none of them worked. Everything was up-to-date, but I couldn't install any new gems or build rubies.
My solution was to:
Remove the ruby version (for me it was 2.1.1)
Brew uninstall ruby-build and rbenv
Brew Re-install rbenv and ruby-build
Hope this helps you if you encounter it too!

Resources