Error installing Ruby 3.1.2 on macOS 12.5 - ruby

I'm trying to install Ruby 3.1.2 on macOS 12.5, using chruby as my version manager.
Running ruby-install ruby, I get this error:
>>> Extracting ruby-3.1.2.tar.xz to /Users/justin/src/ruby-3.1.2 ...
/usr/local/bin/../share/ruby-install/util.sh: line 56: xzcat: command not found
/usr/local/bin/ruby-install: line 46: cd: /Users/justin/src/ruby-3.1.2: No such file or directory
>>> Regenerating ./configure script ...
autoreconf: error: 'configure.ac' is required
!!! Configuration of ruby 3.1.2 failed!
I'm not quite sure how to troubleshoot this. Anybody have some tips for me?

There seems to be an issue in ruby-install tracking this.
I appears that ruby-install currently does not explicitly depend on xz as a dependency although they are required for chruby and ruby-install. Until the new version of ruby-install is fully available on homebrew, you can manually install the xz package with
brew install xz
to make sure xz (and thus the xzcat executable) are available on your system. Afterwards, you should be able to install your Ruby version.

Related

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

gem install - fatal error: 'ruby/config.h' file not found in Mojave

gem install is failing in MacOs Mojave. Anything that can help me solve this? My ruby version is ruby 2.3.7p456.
➜ sudo gem install json -v '1.8.3'
current directory: /Library/Ruby/Gems/2.3.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Update 15/03/2021
According to Apple, Ruby won't be included anymore in future versions of the system, so using a Ruby version manager will be the only way to go once this will actually happen.
Original answer
After hours and hours of trial and errors I wanted to go deeper into the reasons of this error and I finally found this that I think is the clean way to go around this issue:
Catalina (NdMe: I think this started earlier, on Mojave) no longer supports including macOS headers in command line
tools, they have to be explicitly used through Xcode SDK. You can do
so by running gem through the xcrun tool like:
xcrun gem install <your_gem>
Quoted from a Github issue comment.
Xcode 12 upgrade messed this up for me.
I installed ruby from brew and added this to my .zshrc
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
If you have the Xcode 10 beta running this might fix it
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
In macOS Monterey (in the Beta at least), Ruby (ruby 2.6.3p62 (2019-04-16 revision 67580)) is still included but it doesn't seem to work well (fatal error: 'ruby/config.h' file not found), so I installed my own version of Ruby. You can install ruby manually, but I prefer to use rbenv, a Ruby version manager.
Install ruby using rbenv
Install rbenv: brew install rbenv ruby-build
ruby-build is a plugin for rbenv to actually install a ruby version, it provides ruby install command.
Setup rbenv: rbenv init, (and follow its recommended instructions, for example if you're using zsh, it says add eval "$(rbenv init -)" to ~/.zshrc)
Install ruby: rbenv install 3.0.1. Latest version listed here
Do what you came to do: sudo gem install cocoapods or bundle install
Or install ruby manually:
Run brew install ruby
Run echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc so that this version is used
Restart terminal
asdf?
An alternative to rbenv is asdf, but I find asdf a bit complicated to use, since it supports more than just ruby, NodeJS. I would argue it does none of them very ergonomically.
Note: I have an M1 mac, and it's still working.
I got into this issue when trying to install fastlane with homebrew. None of the suggestions mentioned earlier helped me. Manually installing the macOS_SDK_headers_for_macOS_10.14.pkg fixed it.
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
I was having this same issue where I could not install native extensions due to a failure when including "ruby/config.h".
I believe the cause of this issue was because I was using the ruby version installed with Homebrew. After upgrading to a new version of Ruby with Homebrew, I saw the following helpful message from Homebrew:
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
Adding the following lines to my ~/.bash_profile fixed the issue for me:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
xcrun gem install <your_gem> worked for me, but I had to do it multiple times — every time bundle install failed.
The best solution is probably to set the same vars as xcrun in your .zshrc file. xcrun env on my system adds:
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPATH=/usr/local/include
LIBRARY_PATH=/usr/local/lib
I had this problem after installing Big Sur. I found the file ruby/config.h was not present in the Xcode Packages in the Xcode versions I had installed prior to upgrading. I was able to correct it by uninstalling the Xcode versions and reinstalling them.

rbenv fails to install ruby 1.8.7 on MacOS X Sierra

After creating a .ruby-version file with 1.8.7, running rbenv install on the same directory where the file is gives the following error:
ERROR: This package must be compiled with GCC, but ruby-build couldn't
find a suitable gcc executable on your system. Please install GCC
and try again.
DETAILS: Apple no longer includes the official GCC compiler with Xcode
as of version 4.2. Instead, the gcc executable is a symlink to
llvm-gcc, a modified version of GCC which outputs LLVM bytecode.
For most programs the llvm-gcc compiler works fine. However,
versions of Ruby older than 1.9.3-p125 are incompatible with
llvm-gcc. To build older versions of Ruby you must have the official
GCC compiler installed on your system.
TO FIX THE PROBLEM: Install Homebrew's apple-gcc42 package with this
command: brew tap homebrew/dupes ; brew install apple-gcc42
You will need to install the official GCC compiler to build older
versions of Ruby even if you have installed Apple's Command Line Tools
for Xcode package. The Command Line Tools for Xcode package only
includes llvm-gcc.
BUILD FAILED (OS X 10.12.4 using ruby-build 20170405-2-g3b15693)
Then running brew install apple-gcc42 gives:
apple-gcc42: This formula either does not compile or function as expected on macOS
versions newer than Mavericks due to an upstream incompatibility.
Error: An unsatisfied requirement failed this build.
Stuck trying to install ruby 1.8.7 through rbenv on MacOS X Sierra. Any ideas on how to fix this?
Previous answer looks good, but some updates for it:
You must add the following code not after line 762 (because from version to version lines must be different).
You must insert it after:
require_gcc() {
local gcc="$(locate_gcc || true)"
these lines(for me it was 784 line)
So full tutorial:
Found the solution here: http://xibbar.hatenablog.com
http://xibbar.hatenablog.com/entry/2017/04/28/112813
After running it through Google Translate, got to this:
Find ruby-build: which ruby-build
Edit it (in my case): vim /usr/local/bin/ruby-build
Find the lines like these:
require_gcc() {
local gcc="$(locate_gcc || true)"
Add the following code after it:
local osx_version="$(osx_version)"
if [ $osx_version = "1012" ]; then
return 0
fi
Run:
CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=`brew --prefix openssl`" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 1.8.7-p374
Hope it's useful to others.
Found the solution here: http://xibbar.hatenablog.com
After running it through Google Translate, got to this:
Find ruby-build: which ruby-build
Edit it (in my case): vim /usr/local/bin/ruby-build
Add the following code after line 762:
local osx_version="$(osx_version)"
if [ $osx_version = "1012" ]; then
return 0
fi
Run:
CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=`brew --prefix openssl`" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 1.8.7-p374
Hope it's useful to others.

Ruby and "You must recompile Ruby with OpenSSL support or change the sources in your Gemfile"

Using rvm I upgraded my ruby to 1.9.3-p392, also added 2.0.0, anytime I try to use this version when I run my bundle command I get this error.
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using RVM are
available at rvm.io/packages/openssl.
I have followed several different instructions on how to fix this. I have tried removing the version and installing it with the rvm options
--with-openssl-dir=$HOME/.rvm/usr
I have installed OpenSSL with rvm, and macports. Both have not helped the problem. I even changed the file location of the ssl cert using this:
export SSL_CERT_FILE=/Users/DarkLord/.rvm/usr/ssl/cert.pem
No matter what I do I continue to get the error.
Can someone please help me fix this?
This works for me:
rvm get stable
brew install libyaml
rvm pkg install openssl
rvm install ruby-2.0.0 --with-openssl-dir=$HOME/.rvm/usr
rvm use ruby-2.0.0
All credits go to https://coderwall.com/p/tptocq
This helps me install 1.9.3-head on Mac:
rvm get latest
brew install openssl
rvm reinstall 1.9.3-head --with-openssl-dir=`brew --prefix openssl`
In my case after:
1. brew install openssl
2. rvm install ruby-2.6.0
bundle install failed with this error. The problem was that openssl was globally set so I had to install the new ruby version by setting the openssl directory explicitly.
So what I had to do was:
1. rvm reinstall ruby-2.6.0 --with-openssl-dir=/usr/local/opt/openssl
2. rvm reload
Assuming that usr/local/opt/openssl is where it is installed.
After that bundle install ran successfully.
Warning when I tried this command with this path /usr/local like some answers suggested, it didn't work.
To get this working again I had to install homebrew and move my mac ports out of the way. Then do the following after removing 1.9.3-p392 and 2.0.0-p0:
rvm get head --autolibs=3
rvm install 1.9.3 --with-opt-dir=/usr/bin
rvm install 2.0.0
There was something not working with my mac ports and openssl and make and configure. This was the only way I was able to get rvm to install ruby again with out getting openssl issues or make/configure issues.
The new way to do it, according to a comment by #Purplejacket above, is the following:
rvm autolibs homebrew
rvm install 2.1.1
rvm use 2.1.1
It's much easier.
In my case:
Problem: After installing ruby-2.3.1, I ran the command bundle install and then the error occurred.
Solution:
I first installed OpenSSL on my machine. $ brew install openssl
And then, reinstalled the ruby version I require (2.3.1) with the openssl.
$ rvm reinstall 2.3.1 --with-openssl-dir=/usr/local/opt/openssl
And this solved my problem!
According to the following question:
How to tell which openssl lib is actually being used by an RVM-installed ruby
It seems that the options --with-openssl-dir=... is no longer valid as of Ruby 1.9.3. I tried
rvm install 1.9.3 --with-opt-dir=/usr/local --with-openssl
and it worked.
macOS Catalina
brew install rbenv/tap/openssl#1.0
rvm reinstall 2.3.8 --with-openssl-dir=/usr/local/opt/openssl#1.0
The following steps worked for me.
First ensure openssl is installed by running brew install openssl, then reinstall the ruby version using rvm, but this time around, you have to pass the with-opt-dir flag pointing to the location where openssl was installed on your machine (use command which openssl to find this location).
rvm install 1.9.3-p392 --with-openssl-dir=/usr/local/opt/openssl
On macOS 10.14, Ruby 2.5.3, and OpenSSL 1.0.2n this worked for me:
./configure --with-openssl --with-openssl-dir=/usr/local/ssl
but I was only trying what the error messages were telling me:
*** Following extensions are not compiled:
openssl:
Could not be configured. It will not be installed.
/Users/brian/Desktop/Ruby/ruby-2.5.3/ext/openssl/extconf.rb:97: OpenSSL library could not be found. You might want to use --with-openssl-dir=<dir> option to specify the prefix where OpenSSL is installed.
Check ext/openssl/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
make[1]: *** [note] Error 1
I encountered this issue when working on a Ruby 2.2.3 application.
I had previously uninstalled the MySQL database server on my machine, since I did not need it. However, I still needed the mysql2 gem since my application was connecting to another application's MySQL database to pull data.
However, when I try to run the bundle command I get the error:
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using RVM are
available at rvm.io/packages/openssl.
Here's how I solved it:
The issue was caused by removing the libssl-dev library when I was uninstalling the MySQL database server on my machine and its libraries.
First I ran the command below to reinstall ruby since I installed it using rvm:
rvm reinstall ruby-2.2.3
This raised an error:
Making gemset ruby-2.2.3 pristine............................................./-
.'command gem pristine --extensions mysql2 --version 0.5.3' failed, you need to fix these gems manually.
.
Error running '__rvm_with ruby-2.2.3 gemset_pristine',
please read /home/promisepreston/.rvm/log/1630094455_ruby-2.2.3/gemset.pristine-ruby-2.2.3.log
Next, I tried to install the mysql2 gem:
gem install mysql2
Then I ran into this error:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.
Finally, I installed the mysql client library using the command:
sudo apt-get install libmysqlclient-dev
Note: This also installs the libssl-dev library alongside.
And everything worked fine.
That's all.
That's what helped me:
rvm reinstall 2.5
brew tap raggi/ale
brew install openssl-osx-ca
brew services start openssl-osx-ca
Found this solution here: https://github.com/raggi/openssl-osx-ca#readme
I specified a more recent Ruby version in my Gemfile, then ran bundle install. All good now.
Specific case for ruby version 3.0.3
By default for brew and system and autolibs OpenSSL version is 3. Ruby 3.0.3 does not work with OpenSSL version 3 and ruby build silently ignores OpenSSL.
To build ruby properly use build options with OpenSSL 1 like this:
PKG_CONFIG_PATH=/usr/local/opt/openssl#1.1/lib/pkgconfig rvm reinstall 3.0.3 --with-openssl --with-openssl-lib=/usr/local/opt/openssl#1.1/lib --with-openssl-include=/usr/local/opt/openssl#1.1/include
Where path variables may be another - check your system.
Thanks to article Ruby 3.0.3 with OpenSSL using MacPorts and RVM
I got this to work on Ubuntu 22.04 by doing:
rvm pkg install openssl
...and adding --with-openssl-dir=$HOME/.rvm/usr to the rvm install command.
This doesn't seem particularly OS-specific and might work on Mac OS as well.
Fix which worked for me
rvm install 3.0.3 --with-openssl-dir=/opt/homebrew/etc/openssl#1.1
PS. Find the correct openssl location in your machine and install ruby pointing to that path like above, mentioning the brew installed openssl#3 path doesnot work.
I don't use rvm, and I don't want to. I had to install asdf in order to resolve what I used to be able to do with just homebrew & ruby.
Following this guide is the only thing that worked for me after following dozens of suggestions. I had to install asdf and update my .zshrc to include the following at the end of the doc:
eval "$(rbenv init - zsh)"
I'm on an Intel Mac running Monterey 12.2.1.

Problems getting ruby-libvirt extensions to compile Mountain Lion

I bought a new Mac this week and have had big problems getting this gem installed. It was never a problem on my old Mac but seems to be particularly difficult on this one.
I have installed libvirt via Homebrew, Xcode4.4 (with command line tools) and gcc4.2. I have symlinked to make gcc4.2 the default compiler.
gem install ruby-libvirt -v '0.4.0' fails because it cannot find the headers
If I pass in the paths to the headers and libraries, like so:
ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/0.9.11.3/include/ --with-libvirt-lib=/usr/local/Cellar/libvirt/0.9.11.3/lib/
, it compiles just fine but fails when linking with the following errors:
linking shared-object _libvirt.bundle
ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make: *** [_libvirt.bundle] Error 1
I have installed Ruby 1.9.3 via RVM and haven't had any troubles installing other native extensions, so I cannot see why it fails to find the ruby libraries in this case.
Does anyone have any ideas? Help would be much appreciated.
I built ruby-libvirt-0.4.0/ext/libvirt by proving external libvirt installed using brew.
Here is what I did to successfully install libvirt.
brew install libvirt
ruby extconf.rb --with-libvirt-include=/usr/local/include/libvirt --with-libvirt-lib=/usr/local/lib/libvirt
gem install ruby-libvirt -v '0.4.0' -V -- --with-libvirt-include=/usr/local/Cellar/libvirt/1.1.4/include/libvirt --with-libvirt-lib=/usr/local/Cellar/libvirt/1.1.4/lib
Hope this helps.
To install the gem you need to install the libvirt libraries. Using 'Homebrew' (a package manager for mac) :
brew install libvirt
bundle install
The exact error you got might have been:
An error occurred while installing ruby-libvirt (0.4.0)
I have finally solved this. It turns out that the command line tools were not properly installed. The following line needs to be added to your .zshrc file (or whatever applies to your choice of shell):
export PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH
You need only to install libvirt, before the bundle install.
brew install libvirt

Resources