How to add an installed ruby or jruby version to rbenv - ruby

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.

Related

Installing Ruby version using rbenv

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

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

Installing tk/tcl on an existing ruby 2.2 installation in ubuntu 14.04

I saw some fix for previous versions of ruby, unfortunately, it doesn't work anymore for 2.2... Is there a way to add it up to my existing installation, or should I do a reinstall so I can configure ruby to include tk/tcl? Anyways, I'm using rbenv as my version manager.
Had the same issue as I think you have(/had?). I'm running ruby 2.2 on ubuntu 14.04 installed using rbenv. When I tried
require 'tk'
I got:
cannot load such file -- tk
After a lot of fidgeting around I finally made it work by downloading ActiveTCL from http://www.activestate.com/activetcl/downloads (I got version 8.6.4), unpacked it and installed it using
sudo ./install.sh
I also added the bin folder of ActiveTcl to my path (updated my ~/.profile), on my installation it is: /opt/ActiveTcl-8.6/bin/
then uninstalling the ruby version using
rbenv uninstall 2.2.2
And reinstalling it using
rbenv install 2.2.2
After that I can now require tk and not get any error.

How to use a certain ruby version?

I try to run a script on a LFS Batchsystem. The cluster offers an older version of ruby, so I had to install my gems and rvm locally on my account. Is there a way to run my local installed ruby version on a batch system? My script works fine on my account but not on LFS because mechanize depends on a newer ruby version.
Make sure you have rvm then
rvm use 1.9.3
or to set the default:
rvm use --default 1.9.3
And obviously, replace 1.9.3 with the version you want to use
Create .rvmrc file in your working directory in that you would mention which version of ruby you are going to you like:
rvm use 1.9.3#gemsetname --create
Now you can install all gems for this particular gemset.
I solved my problem with directly using the binary version and to define my local gem folder:
GEM_HOME=/home/my_name/.rvm/gems/ruby-2.0.0-p195/gems
/home/my_name/.rvm/bin/ruby-2.0.0-p195 my_script.rb
The other solutions do not work, because rvm is not available on the cluster.

reinstall every gem for each ruby version?

I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0
The `rails' command exists in these Ruby versions:
1.9.3-p327
Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?
As seen here:
You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:
rbenv whence bundle
See your current version:
rbenv version
Install bundler for that version, if missing:
gem install bundler
Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.
If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.
Another solution to this is to copy (or reinstall) the gems from your previous version to the newly installed version. How to do that is answered in detail in this question, which has two scripts -- one to install from local cache, one to reinstall from the internet (mine).

Resources