Rbenv not persisting installed ruby-version - ruby-on-rails

I Already installed ruby 3.0.2 using rbenv, but it keeps showing the error:
ruby-3.0.2' not installed
T!ll3: ~ () $ cd calendar/
Required ruby-3.0.2 is not installed.
To install do: 'rvm install "ruby-3.0.2"'
T!ll3: ~/calendar () [main] $ rbenv local ruby-3.0.2
rbenv: version `ruby-3.0.2' not installed
T!ll3: ~/calendar () [main] $ rbenv install 3.0.2
rbenv: /home/tille/.rbenv/versions/3.0.2 already exists
continue with installation? (y/N) ^C
T!ll3: ~/calendar () [main] $ rbenv versions
* 3.0.2 (set by /home/tille/calendar/.ruby-version)
do I have to set something in order to always expose the ruby version?
I tried with:
rbenv global 3.0.2 and rbenv local 3.0.2
but didn't work

Related

Ruby version `ruby-3.1.2' is not installed after spring stop

Truly I don't get it what is wrong. I've got fresh project with Rails 7 and Ruby 3.1.2 which I thought I had installed successfully, based on my iTerm2 console:
$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
But after firing up the command spring stop inside my project path I'm getting this weirdo:
➜ merchant-portal git:(main)$ spring stop
rbenv: version `ruby-3.1.2' is not installed (set by /Users/some_user/merchant-portal/.ruby-version)
What's going on?
I tried installing the Ruby 3.1.2 again but I'm getting another weirdo:
$ rbenv install 3.1.2
Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
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/bw/rs138g1n5zv_qwn7_7kggc9r0000gq/T/ruby-build.20220801173008.20865.CTLYIi
Results logged to /var/folders/bw/rs138g1n5zv_qwn7_7kggc9r0000gq/T/ruby-build.20220801173008.20865.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/some_user/.rbenv/versions/3.1.2
--with-openssl-dir=/Users/some_user/.rbenv/versions/3.1.2/openssl
--enable-shared
--with-readline-dir=/usr/local/opt/readline
CC=clang
LDFLAGS=-L/Users/some_user/.rbenv/versions/3.1.2/lib
CPPFLAGS=-I/Users/some_user/.rbenv/versions/3.1.2/include
I've tried to reinstall xcode with:
$ rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
(...)
Done
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
And again reinstall Ruby 3.1.2 but it shows me the same error:
$ rbenv install 3.1.2
(...)
BUILD FAILED (macOS 12.5 using ruby-build 20220726)
(...)
Last 10 log lines:
The Ruby yaml extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
(...)
I've also tried to:
RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl` --with-readline-dir=`brew --prefix readline` --with-libyaml-dir=`brew --prefix libyaml`" rbenv install 3.1.2
But it shows me the same error.

running sudo gem install fastlane -NV throws the error installing fastlane rubyzip requires ruby version >= 2.4 when

running
sudo gem install fastlane -NV
throws the error installing fastlane rubyzip requires ruby version >= 2.4 when
Initially, environment setup was done by running the following steps -
First uninstall rvm if it is installed -
rvm -v
rvm list
rvm uninstall {version_to_uninstall}
rvm use system - Switch to macOS default ruby version
rvm implode - uninstall rvm
rbenv - Ruby Environment Manager - we will use this to install ruby
brew install rbenv ruby-build
rbenv install 2.3.7
Add the following line to .bash_profile -
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
source ~/.bash_profile
rbenv global 2.3.7
ruby -v
bundle install
bundle exec fastlane bootstrap
open ProjectName.xcworkspace
Fixed by changing ruby version to 2.6.0 as follows -
rbenv install 2.6.0
rbenv global 2.6.0
Then -
sudo gem install fastlane -NV

Installing Ruby on Rails on a new Mac OS Sierra

I am learning to code and trying to make the move for a Rails project from a cloud dev environment to a local one on my Mac with OS Sierra. However, I am having trouble setting up my ruby version and installing rails.
I have installed Homebrew which I used to install rbenv. Using rbenv I have installed ruby 2.4.0 and set it to local and global. I can see it in .rbenv/versions, however when I check my ruby version I still get 2.0.0
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
When I try and install Rails I get the following;
$ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I am not sure how I utilize the rbenv ruby version in my system to then install rails.
You probably need to add rbenv to your ~/.bash_profile:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
Then source it:
source ~/.bash_profile
Then you can use the rbenv command:
# install a Ruby version:
$ rbenv install <version>
# show versions currently installed and indicate current version
$ rbenv versions
# set ruby version for a specific dir
$ rbenv local <version>
# set ruby version globally
$ rbenv global <version>
# list all available versions:
$ rbenv install -l
The rbenv command is used to install, switch between versions, etc.

Ruby version issues with Rbenv

I am setting up my new machine (Mac Yosemite) and when I run the command "bundle" I get the following error:
Your Ruby version is 2.2.1, but your Gemfile specified 2.2.0
I'm trying to change the version w Rbenv but I think it's not working.
ruby -v
// Ruby 2.2.1p85
rbenv version
// 2.2.0
Can anyone help me? Thanks in advance!
Try to use rbenv local [version number].Refer to this for more understanding.
I had a similar problem but with ruby -v 2.2.0 and Mac OSX El Capitan. What finally worked for me was:
gem install bundler (apparently it was no longer installed)
rbenv rehash
bundle install
I was able to find the answer on the github for rbenv.
https://github.com/sstephenson/rbenv/issues/697
Assuming you have Ruby -v 2.2.0 installed (rbenv install 2.2.0 otherwise), change your ruby version with rbenv:
rbenv global 2.2.0
after install rails you must do this: rbenv rehash, in order to tell rbenv to see rails as executable.
follow this tutorial to set up Ruby and Ruby on Rails in your machine: https://gorails.com/setup/osx/10.10-yosemite
Note: In my case. after install rbenv the command rbenv global 2.2.0 doesn't affect my current ruby version (ruby -v still be the previous one). I fix this issue reinstalling rbenv and run this command:
# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
immediately afterwards, as explained above in the tutorial.

rbenv Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2 but the only version installed is 2.1.2

I'm using rbenv but I can run my server with: rails s
display me an error with:
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2
I tried uninstall the version 2.0.0 but this version doesn't exist
rbenv unistall 2.0.0
And I tried with:
rvm implode
-bash: rvm: command not found
because I'm not using rvm, what I can do to run my server?
And my ruby build says:
$ ruby-build --version
ruby-build 20141113
You just need to install Ruby 2.1.2. You can have multiple Ruby versions installed at the same time. If you have ruby-build installed you can do the following: install 2.1.2, rehash your shims, and then tell rbenv to use 2.1.2 for this project.
rbenv install 2.1.2
rbenv rehash
rbenv local 2.1.2
You're going to have to gem install bundler and then bundle install on your project afterwards.

Resources