Installing Ruby version using rbenv - ruby

I have been trying to install React Native into my Mac. In the installation docs, it requires Ruby version of 2.7.6 have been to be installed.
I have installed a new Ruby version using rbenv manager and it was successful. But now I cannot switch my machine to new Ruby version. Any help will be highly appreciated.
Thanks!

You have to set the version for the directory where your react project is. You can do this with:
rbenv local 2.7.6
This creates a file called .ruby-version in the directory, which tells rbenv what version of Ruby to use.
This is all visible in the README of rbenv.

You can have a look at this solution
Use the below command to change your ruby version:
rbenv global 3.1.2 # set the default Ruby version for this machine
# or:
rbenv local 3.1.2 # set the Ruby version for this directory
You can find this from rbenv Official Github Repo

Related

Building new project gives error rbenv: version `2.7.6' is not installed

on building my new react native project with react native 0.70 using npx react-native init command it gives error while installing bundler that
rbenv: version `2.7.6'
is not installed (set by /Users/rahul/Documents/projects/reactNativeProjects/project1/.ruby-version)
current ruby version 2.7.5p203 on ruby -v
rbenv version: 1.2.0-48-g6717c62 on rbenv -v
on running rbenv install 2.7.6
it shows like this
When you are creating a project . By default it get created at react-native latest version whihch is 0.71 requires a ruby version of 2.7.6 .
You have to install the ruby of that specific version. You can install it by following this link
The error is fairly self explanatory. I'll assume that Ruby 2.7.6 is not installed. To install the Ruby version run:
rbenv install 2.7.6
Once installed update the version you're using. Assuming you're in your project folder you can update the local version by changing the .ruby-version file. This can be done with a rbenv command as well:
rbenv local 2.7.6
Which will update the .ruby-version file for you (assuming that you're in the correct working directory).
Finally validate that the new Ruby version is installed and in use.
ruby --version
Should print 2.7.6

How do I switch my Ruby version for a single project only?

I was reading that rbenv can be used to switch the Ruby environment for a single project only. I have Ruby 2.4 installed on my system, but I'd like to use version 2.3 for a specific project only. I thought using "rbenv local" would heal the pain but it does not ...
localhost:myproject davea$ rbenv local 2.3.0
localhost:myproject davea$ bundle install
Your Ruby version is 2.4.0, but your Gemfile specified 2.3.0
localhost:myproject davea$ ruby -v
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
How do I use Ruby 2.3 for this project only?
rbenv local only sets a .ruby-version file in your current directory, it doesn't also load that version for you. You'll need to set it and then cd .. && cd - to have the rbenv shim pick up that version.
If you have a gemfile you can also add
ruby '2.3.1'
inside it to tell your system to use that ruby version.
This is the best solution for a linux or WSL distribution
Check first what the versions you can download
rbenv install -l
then install it with
rbenv install 2.6.6
now you have installed a version to check all version you have:
rbenv versions
then to use it you can set it locally in a specific project:
rbenv local 2.6.6
or globally
rbenv global 2.6.6
After the installation you could create a projet with rails new ==> automaticaly set with ruby global
If the project are alwready created, there 2 ways
Manually modify:
.ruby-version to your global version
or run in folder of the projet rbenv local 2.6.6
What worked for me was #tadman's solution:
rbenv local 2.7.1 # switches to ruby 2.7.1

I cannot update Ruby on Homebrew from 2.0.0 to 2.3.1

I am trying to upgrade Ruby because I need to setup a Jekyll template, and I need to latest version to do it. Since I have a Mac running Sierra, I already have Ruby preinstalled as well as the Homebrew installation. When I install it using brew install ruby, it works, but when I check the version, it is still at 2.0.0 instead of 2.3.1 where it should be. Homebrew says I have 2.3.1, but the CLI says I have 2.0.0. I tried to use brew link --override ruby to make it work, but it said everything was working and it got me nowhere.
Use rbenv and plugin ruby-build. It will keep several versions of ruby on the one machine.
After install go to directory with your code, run rbenv install 2.3.1 and create file .ruby-version containing 2.3.1. All scripts running from this directory will use ruby 2.3.1.
Or you will able to set ruby version for all running scripts - rbenv global 2.3.1

Puppet is pointing to the older version ruby installed

I'm installing ruby latest version (2.2.1) using RVM on CentOS. & set it as default version. following this link :-
http://tecadmin.net/install-ruby-1-9-3-or-multiple-ruby-verson-on-centos-6-3-using-rvm/
Here my assumption is that i have latest ruby version & set as by default.
Ruby 1.8 ships by default with CentOS.
Now when i'm running puppet server to install some default module it is still pointing Ruby 1.8. using following link : https://forge.puppetlabs.com/puppetlabs/aws#installing-the-aws-module
All i wanted to achieve is installing latest ruby or may be Ruby 1.9.3 version and configuring puppet with the same ruby version.
You are using root and it will use the PATH for the root not the regular user under RVM. Unless of course you installed RVM with the root user which is not recommended.

How to add an installed ruby or jruby version to rbenv

I am trying to set up a jruby environment with rbenv on a box that doesn't have an internet connection. I sucessfully managed to install jruby in /opt/jruby-1.7.11 but don't know to make rbenv recognize that installation.
Create a symlink to your installed jruby version from within ~/.rbenv/versions/ for rbenv to recognize it.

Resources