ruby not found but 2.4.0 installed by rvm indeed - ruby

I am new to Ruby. Following the tutorials: https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rvm-on-ubuntu-16-04 and https://scotch.io/tutorials/a-crash-course-in-ruby.
The output of terminal (OS ubuntu 16.04):
me#xxx:~$ rvm list
rvm rubies
=* ruby-2.4.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
me#xxx:~$ ruby --version
The program 'ruby' is currently not installed. You can install it by typing:
sudo apt install ruby
me#xxx:~$ rvm use ruby-2.4.0
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Any idea why? Thanks.
UPDATE
me#xxx:~$ rvm alias create default 2.4.0
Creating alias default for ruby-2.4.0....
me#xxx:~$ ruby -v
The program 'ruby' is currently not installed. You can install it by typing:
sudo apt install ruby
UPDATE2
Part of ~/.bashrc
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
The last line added by me just now. Still not working.

Theres different ways to install ruby, you can try with rbenv, i did it with this guide and it worked perfectly, maybe u can give it a shot:
https://gorails.com/setup/ubuntu/16.04

Generally, you just have to make sure that your bash is run with the option
--login
(in the config of your terminal) and restart your console.

maybe following code can help you.but I don't know how to deal with it perpetually.
$ source ~/.bashrc
$ source ~/.bash_profile

Related

Ubuntu ruby version keeps changing even after specifying default version in rvm

I want to use ruby 2.3.4 for my rails application which I have installed using rvm on Ubuntu 16.04.
after using command rvm list.
rvm rubies
=* ruby-2.3.4 [ x86_64 ]
# => - current
# =* - current && default
# * - default
but when i use ruby -v I get.
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
so I used rvm --default use 2.3.4.
which does change the version to 2.3.4 when I check using ruby -v but when I restart the terminal or system it changes back to 2.5.0
I want to know how to include 2.5.0 into rvm or remove it.
Check that .bash_profile contains below lines:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Check .bashrc, .zshrc, .mkshrc file contains below lines at end of file:
export PATH="$PATH:$HOME/.rvm/bin"
if not then,
First Run below command then follow link to install rvm:
rm -rf ~/.rvm
RVM Install

System and rvm Ruby versions are different

I installed rvm and used it to install Ruby. According to rvm my current and default version is 2.1.0 however ruby -v gives me two options and neither is the version listed as the default by rvm. What am I missing?
Thanks in advance!
foo#ua41f725e9ecd517ff31d:~$ rvm list
rvm rubies
=* ruby-2.1.0 [ x86_64 ]
# => - current
# =* - current && default
# * - default
foo#ua41f725e9ecd517ff31d:~$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby1.8
* ruby1.9.1
Try: sudo apt-get install <selected package>
You need to make sure that the place where rvm installs the ruby binaries is in your $PATH.
Try adding the following to your .bashrc, .bash_profile, or .zshrc or whatever shell you are using.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
The Ruby installed by rvm isn't in your PATH. That message you saw at the bottom was the system telling you it couldn't find any Ruby version. Be sure that rvm is setting your PATH up correctly.

Ruby 1.8.7 upgrade to ruby 1.9.2

I am going through this tutorial, but I already had Ruby 1.8.7 installed. I need to have 1.9.2/1.9.3 version.
I started to use RVM.
$ rvm list rubies
rvm rubies
ruby-1.8.7-p358 [ x86_64 ]
ruby-1.9.2-p318 [ x86_64 ]
=* ruby-1.9.2-p320 [ x86_64 ]
ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
but if I run ruby -v it returns still 1.8.7.
$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
other return values:
$ whereis ruby
ruby: /usr/bin/ruby /usr/bin/ruby1.8 /usr/lib/ruby /usr/share/man/man1/ruby.1.gz
$ which rails
/usr/local/bin/rails
$ which ruby
/usr/bin/ruby
When you're typing ruby you're still hitting the system ruby, not the rvm ruby.
Did you follow all the directions here: https://rvm.io//rvm/install/ ?
It looks like you're running Linux -- did you see this section in the rvm install docs?
If you open a new shell and running:
$ type rvm | head -1
does not show "rvm is a function", RVM isn't being sourced correctly.
Ensure that RVM is sourced after any path settings as RVM and manipulates the path. If you don't do this, RVM may not work as expected.
If you are using GNOME on Red Hat, CentOS or Fedora, ensure that the Run command as login shell option is checked under the Title and Command tab in Profile Preferences. After changing this setting, you may need to exit your console session and start a new one before the changes take affect.
Also, rvm adds some lines to your .bashrc file to load itself into memory whenever you open a console session. It looks like this may be your issue.
In my .bashrc, for example, rvm inserted the following:
export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/postgresql84/bin:$PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Is there something similar in yours? Also, if you're using z-shell you may need to take some extra steps that are outlined in the install docs.
Try
$ rvm use ruby-1.9.2-p320
then
$ ruby -v
what does this return?
This should change your ruby version to ruby-1.9.2-p320 in the current console and if you want it on every new opened terminal you may use --default option
try
$ rvm --default use ruby-1.9.2-p320
then
$ruby -v
should return ruby-1.9.2-p320 version in the current and in every new window terminal opened.
Any time you want to return to your system ruby installation
use
$ rvm use system

Why does Ruby or RVM seem stuck at 1.8.7 on Linux Mint?

I am on Linux Mint 12.
I installed RVM and ran these commands:
rvm 1.9.2
rvm --default use 1.9.2
but ruby -v still outputs ruby 1.8.7.
sudo apt-get install ruby1.9.2 returns saying 1.9.1 is the latest version.
How do I get Ruby to be running on 1.9.2?
When I run rvm list like suggested at "Ruby 1.9.2 keeps reverting back to 1.8.7 after installing it using RVM", it outputs:
rvm rubies
ruby-1.8.7-p352 [ x86_64 ]
=> ruby-1.9.2-p290 [ x86_64 ]
So I think I must have a configuration issue. My OS seems to be defaulting to the wrong version of Ruby.
I ran:
sudo apt-get remove ruby
But had no change.
You add string [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" into ~/.bashrc? First, show your echo $PATH output. If this looks like (rvm paths before system paths):
/home/ayunin/.rvm/gems/ruby-1.9.3-rc1/bin:/usr/bin:/bin:/usr/bin/X11
Then you ran into the magick. Restart your terminal, and show ruby version. If does not work - you can launch rvm implode and reinstall all, yes.
It looks like Linux Mint 12 has ruby-rvm already installed (at least on my machine) so could this be a problem?
you can stick with that but then I think you will need to add your username to the rvm group with usermod -a -G username rvm.
I removed removed ruby-rvm completely (with apt-get) and then followed the installation instructions from https://rvm.beginrescueend.com/rvm/install/ for 'single user' thus all my rvm files are located in ~/.rvm/bin/rvm
I added the line for rvm in my .bashrc and tested with 1type rvm | head -1`.
After that rvm install 1.9.2 just worked and I installed it into ~/.rvm/rubies/ruby-1.9.2
After that rvm use --default 1.9.2 set all up correctly.

Using RVM, but can't set current Ruby version (Ubuntu 11.10)

I have recently installed RVM on a fresh install of Ubuntu 11.10 and can not work out how to start using a particular ruby version.
I have installed Ruby 1.8.7 and 1.9.2, and they show up in the list fine:
$ rvm list
rvm rubies
ruby-1.8.7-p352 [ i386 ]
ruby-1.9.2-p290 [ i386 ]
When I try to use the "use" command, everything seems fine:
$ rvm use 1.9.2
Using /usr/share/ruby-rvm/gems/ruby-1.9.2-p290
Running /usr/share/ruby-rvm/hooks/after_use
But then when I test the current ruby version, I get the usual Ubuntu 11.10 message you get when you don't have RVM at all:
$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby1.8
* ruby1.9.1
Try: sudo apt-get install <selected package>
What am I doing wrong? Did I miss out a step in the RVM installation or something?
EDIT*
Answers to some comments:
$ which ruby
#returns nothing at all.
$ which rvm
/usr/bin/rvm
$ rvm -v
rvm 1.6.9 by Wayne E. Seguin (wayneeseguin#gmail.com) [https://rvm.beginrescueend.com/]
$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
RVM 1.6.9 is very old now. Did you install it through some package manager? If so, get rid of it and run the following in your bash shell:
curl -L https://get.rvm.io | bash -s stable
Then, place [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" in ~/.profile OR ~/.bash_profile OR ~/.bashrc
You should then be able to run type rvm | head -n 1 and it should say "rvm is a function".
Then you should be able to install rubies and use one of them. Be sure to use --default for that Ruby to remain the default even after you end your terminal session. E.g. rvm use ruby-1.9.2-p290 --default
Have you added the following line to your .bash_profile,
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
as the installation page for rvm says?
Like tass suggested you obviously have a different rvm directory then $HOME/.rvm so
[[ -s "/usr/share/ruby-rvm/scripts/rvm" ]] && . "/usr/share/ruby-rvm/scripts/rvm"
is probably what you would to use instead
I know this thread is zombie-old, but in your terminal client's preferences, checking 'run command as login shell' solved it for me. RVM generally puts that line in your ~/.bash_profile for you.

Resources