I'm trying to install Ruby for programming on my macOS Monterey with Apple M1 chip.
I started off by following these steps:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Ok, great! That works...
brew install rbenv
This also worked. I double checked and got: rbenv 1.2.0 is already installed and up-to-date.
rbenv init
This outputs this: eval "$(rbenv init - zsh)" so I change it to that, close terminal, and relaunch it.
rbenv install 3.0.4
And this gets this:
ME#0107 ~ % rbenv install 3.0.4
Downloading openssl-1.1.1q.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/d7939ce614029cdff0b6c20f0e2e5703158a489a72b2507b8bd51bf8c8fd10ca
Installing openssl-1.1.1q...
patching file test/v3ext.c
Installed openssl-1.1.1q to /Users/ME/.rbenv/versions/3.0.4
Downloading ruby-3.0.4.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.4.tar.gz
Installing ruby-3.0.4...
ruby-build: using readline from homebrew
BUILD FAILED (macOS 12.5 using ruby-build 20220726)
Inspect or clean up the working tree at /var/folders/bn/gcvl_htn4lz2y2d9h215n0vc0000gn/T/ruby-build.20220814230938.91093.ruEkdU
Results logged to /var/folders/bn/gcvl_htn4lz2y2d9h215n0vc0000gn/T/ruby-build.20220814230938.91093.log
Last 10 log lines:
The Ruby yaml extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Configure options used:
--prefix=/Users/ME/.rbenv/versions/3.0.4
--with-openssl-dir=/Users/ME/.rbenv/versions/3.0.4/openssl
--enable-shared
--with-readline-dir=/opt/homebrew/opt/readline
CC=clang
LDFLAGS=-L/Users/ME/.rbenv/versions/3.0.4/lib
CPPFLAGS=-I/Users/ME/.rbenv/versions/3.0.4/include
ME#0107 ~ %
Here's where it gets crazy:
I type in: rbenv global 3.1.2
No output... If I typed anything else, terminal would say:
rbenv: version `3.0.2' not installed
but then I type... ruby -v
And I get...
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]
Any help would be greatly appreciated.
You can run arch -arm64 rbenv install 3.0.4 and it should install without issues on M1 Chips Devices.
Related
Ultimately I'm trying to install Cocoapods which generates error:
Building native extensions ERROR: Error installing cocoapods ERROR: Failed to build gem native extension
..which I assume is because ruby is not latest (stuck at 2.6).
I tried
brew install ruby
and
brew reinstall ruby
...still at v2.6
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew install ruby
Updating Homebrew...
Warning: ruby 3.0.1 is already installed and up-to-date.
To reinstall 3.0.1, run:
brew reinstall ruby
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
DOUGs-MacBook-Pro:LOCATION dbell$ brew reinstall ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.1
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/6d2a0e9cda0072647ac4fcb119f4f0263b91503dc918ba80d057da0897a3f994--ruby-3.0.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:1af6edba23ff9aa12fcab0fee9246cf46110263bf962e46e800152096b0c7017
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/7d7455d376fe2f0401873034dc82e6daae1f05efe465847b4db1464a73155c8f--ruby--3.0.1.catalina.bottle.tar.gz
==> Reinstalling ruby
==> Pouring ruby--3.0.1.catalina.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/3.0.0/bin
You may want to add this to your PATH.
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"' >> ~/.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"
==> Summary
🍺 /usr/local/Cellar/ruby/3.0.1: 16,358 files, 38.4MB
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$
I tried restarting Mac. Still 2.y
The best way to use ruby on mac is to use ruby version manager. I use rbenv. It allows you easly to switch between different ruby versions and doesn't cause conflicts.
To install it run brew install rbenv ruby-build
then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
and finally source ~/.bash_profile
now install any ruby for example 3.0.0 by typing rbenv install 3.0.0
and set it globally
rbenv global 3.0.0
edit: This may not work if you're using different shell. Check what shell is your default by running echo $SHELL
If your default shell is zsh, then instead of your second and third steps run:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
/Users/mike/.rvm/gems/ruby-2.7.0/gems/cocoapods-core-1.9.1/lib/cocoapods-core/cdn_source.rb:337: warning: URI.escape is obsolete
Looks like the upcoming CocoaPods 1.10.0 will remove the deprecation warnings. See https://github.com/CocoaPods/CocoaPods/issues/9491. In the mean time, I wouldn't worry about it. These are just warnings and shouldn't currently cause any issues.
If you really want to remove the warnings you can disable all Ruby warnings using the RUBYOPT environment variable like this:
export RUBYOPT='-W0'
Although I wouldn't recommend it as you risk missing something important in the future.
upgrading ruby to 2.7.2 and reinstall cocoapods 1.10.0 can fix
brew upgrade ruby
gem install cocoapods
Same problems with ruby 2.7.1 and 2.7.2 but SOLVED for me with installing ruby 2.6.6:
if you don't have homebrew installed:
install homebrew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
install rbenv (version manager): brew install rbenv ruby-build
prepare a terminal: echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile source ~/.bash_profile
install Ruby: rbenv install 2.6.6
activate the version: rbenv global 2.6.6
verify the activated version: ruby -v
then reinstall cocoapods: sudo gem install cocoapods
and in the app folder run:pod install
Try the following:
sudo gem install cocoapods
First, remove old cocoapods:
sudo gem uninstall cocoapods
Then, install it again and override:
brew install cocoapods --build-from-source
brew link --overwrite cocoapods
It worked for me after upgrating to Catalina
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)"
I run brew update and brew upgrade rbenv ruby-build. FYI: I updated xcode to version 8.1 yesterday.
I checked available versions, rbenv install -l.
Then I tried to install ruby2.2.5 by rbenv install 2.2.5, then I get the following errors.
I tried 2.3.1 but I got the same errors. How can I fix the problem?
Downloading ruby-2.2.5.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.5.tar.bz2
Installing ruby-2.2.5...
BUILD FAILED (OS X 10.11.6 using ruby-build 20160602)
Inspect or clean up the working tree at /var/folders/2p/49l6q0gs6qzgtxbg4h1st_5h0000gq/T/ruby-build.20161106122840.51330
Results logged to /var/folders/2p/49l6q0gs6qzgtxbg4h1st_5h0000gq/T/ruby-build.20161106122840.51330.log
Last 10 log lines:
Referenced from: /private/var/folders/2p/49l6q0gs6qzgtxbg4h1st_5h0000gq/T/ruby-build.20161106122840.51330/ruby-2.2.5/./miniruby (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _clock_gettime
Referenced from: /private/var/folders/2p/49l6q0gs6qzgtxbg4h1st_5h0000gq/T/ruby-build.20161106122840.51330/ruby-2.2.5/./miniruby (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
make: *** [encdb.h] Trace/BPT trap: 5
make: *** Waiting for unfinished jobs....
make: *** [.rbconfig.time] Trace/BPT trap: 5
First, I've uninstalled all:
brew uninstall rbenv ruby-build
and because of an old sticky ruby-build installation, I've forced like this:
brew uninstall --force ruby-build
I can see an old invocation for rbenv when I type ruby -v. So I remove all rbenv references from $HOME/.bash_profile and then reload it with:
source $HOME/.bash_profile
Now I only see my old default MacOs ruby version:
ruby -v # ruby 2.0.0p481 (2014-05-08 revision 45883)
which ruby # /usr/bin/ruby
¡Good! Now it's time to install them again and then list available Ruby versions:
brew install rbenv
rbenv install -l
I now can see more Ruby options to install...
2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.3.0, 2.3.1, 2.3.2, 2.3.3, 2.3.4, 2.3.5, 2.3.6, 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.5.0
I will choose one of them and make it global:
rbenv install 2.5.0
rbenv global 2.5.0
I case you don't have already the $HOME/.bash_profile rbenv config line, run:
rbenv init
... and add the resulting line to your $HOME/.bash_profile.
I tried to upgrade rbenv.
brew upgrade rbenv
Then I got a warning.
Warning: You have Xcode 8 installed without the CLT;
this causes certain builds to fail on OS X El Capitan (10.11).
Please install the CLT via:
sudo xcode-select --install
Error: rbenv 1.0.0 already installed
So I installed xcode-select.
sudo xcode-select --install
Then I tried to upgrade rbenv but rbenv 1.0.0 was already installed.
brew upgrade rbenv
Error: rbenv 1.0.0 already installed
So I tried to install 2.3.1 and 2.2.5
rbenv install 2.3.1
...
rbenv install 2.2.5
And it was a success.
➜ ~ rbenv versions
system
1.9.3-p327
* 2.2.2 (set by /Users/sokada/.rbenv/version)
2.2.5
2.3.1
I also need to install bundle since I came to this problem from using bundle.
gem install bundler -v 1.13.6 // newest as of this writing
bundler -v
bundler install // finally I could use it.
It's a really old question. However, the correct approach I believe is to upgrade ruby-build. It is available as a plugin for rbenv that provides the rbenv install command.
so to fix the issue follow this approach: https://github.com/rbenv/ruby-build#upgrading
# Via Homebrew
$ brew update && brew upgrade ruby-build
In Ubuntu 10.04 I just installed rbenv.
The install command is not present.
rbenv 0.4.0-49-g8b04303
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme
What am I missing?
The install command is not embedded into rbenv, it comes from the ruby-build plugin. You can install it using the command:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
On Mac OS X you can install it through homebrew:
brew install ruby-build
On Debian (version >= 7) and Ubuntu (version >= 12.10) both rbenv and ruby-build can be installed using apt-get (or aptitude):
sudo apt-get update
sudo apt-get install rbenv ruby-build
On FreeBSD ruby-build is available in the Ports Collection, it can be install both as a binary package or build from the port:
# Using pkgng rbenv will be installed
pkg install ruby-build
# Building ruby-build form Ports will install rbenv only if the RBENV option is set
cd /usr/ports/devel/ruby-build
make install
I found that when using rbenv from a global directory, it's necessary to export the RBENV_ROOT variable, otherwise it won't load the plugins.
export RBENV_ROOT="/usr/local/rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
fi
As everyone mentioned problem is missing ruby-build. For older versions of OS ruby-build may not be available as an apt package. In that case install using original instructions, which should've omitted the word Optional in this:
(Optional) Install ruby-build, which provides the rbenv install
command that simplifies the process of installing new Ruby versions.
git clone git#github.com:rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# OR use http
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Simply install ruby-build in ubuntu:
sudo apt-get install ruby-build
And add
eval "$(rbenv init -)"
To your ~/.bashrc
I had installed the ruby-build plugin before and installed ruby 1.9.3-p327 using
$ rbenv install 1.9.3-p327
A few days later I tried to install ruby 2.0.0-p247 using
$ rbenv install 2.0.0-p247
but I received the error message
rbenv: no such command 'install'
All I had to do was to run
$ exec $SHELL -l
and that fixed the problem.
Answered on 2021
If you're getting that error, it's very likely you have accidentally skipped one of the installation instructions:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
Replace .bashrc with whatever shell you're using, for example .zshrc, or just manually access your shell config file and paste this line:
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
I strong advise against re-installing/installing Ruby via brew or apt-get just to get around this issue. The whole point of using rbenv is to make your life easier in future when there is ruby version upgrade, or when you're working on different rails projects that require different version of ruby.
It looks like ruby-build is not present. Run this command :
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
Anyone finding their way here with this issue on OSX and already having installed ruby-build via homebrew (like me), you may solve this by just upgrading ruby-build:
brew update
brew upgrade ruby-build
This fixed the problem for me.
This issue also happens in Linux when doing a stand-alone installation of ruby-build, if the ruby-build executable is not found in the path. If installing under /usr/local, try for example:
PATH=/usr/local/bin:$PATH /usr/local/bin/rbenv install ...
I came to this solution, but looking for a macOS solution that uses MacPorts.
So, here the same command using MacPorts:
➜ ~ sudo port install ruby-build
Password:
---> Computing dependencies for ruby-build
---> Fetching archive for ruby-build
---> Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2 from https://packages.macports.org/ruby-build
---> Attempting to fetch ruby-build-20210804_0.darwin_19.noarch.tbz2.rmd160 from https://packages.macports.org/ruby-build
---> Installing ruby-build #20210804_0
---> Activating ruby-build #20210804_0
---> Cleaning ruby-build
---> Scanning binaries for linking errors
---> No broken files found.
---> No broken ports found.
➜ ~ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Checking for `rbenv' in PATH: /opt/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /opt/local/bin/rbenv-install (ruby-build 20210804)
Counting installed Ruby versions: none
There aren't any Ruby versions installed under `/Users/user/.rbenv/versions'.
You can install Ruby versions like so: rbenv install 3.0.2
Checking RubyGems settings: OK
Auditing installed plugins: OK
➜ ~ rbenv install 3.0.2
Downloading openssl-1.1.1k.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5
Installing openssl-1.1.1k...