change ruby version with rbenv - ruby-on-rails

I have just installed rbenv and try to use it, I have unistalled rvm.
I am now trying to use 2.3.3 version of ruby.
rbenv local
2.3.3
rbenv global
2.3.3
ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

Related

Rails using a different version of Ruby from the rest of the sytem?

My installation of Rails seems to be using a different version of Ruby from the version of Ruby on the rest of my system:
$ rails --version
Rails 5 requires Ruby 2.2.2 or newer.
You're running
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
Please upgrade to Ruby 2.2.2 or newer to continue.
$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
Why is this? I installed Rails with sudo gem install rails. I'm on OSX and don't remember how I installed Ruby.
Mac OSX comes ruby installed as default. If you need more late versions of ruby, you need to follow this guide: http://railsapps.github.io/installrubyonrails-mac.html

Capistrano 3: incompatible ruby version

I am deploying a rails app to Ubuntu 14.04 using Capistrano.
In remote Ubuntu server it shows I am using Ruby 2.3.0
I tried these commands to install Ruby
rbenv install 2.3.0
rbenv global 2.3.0
rbenv rehash
deploy#ubuntu:~$ rbenv versions
system
* 2.3.0 (set by /home/deploy/.rbenv/version)
deploy#ubuntu:~$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
But when I try cap production deploy, error happens and shows a different Ruby is working, instead of 2.3.0
activesupport-5.0.0.1 requires ruby version >= 2.2.2, which is
incompatible with
the current version, ruby 1.9.3p484
How can I fix this?

After installing ruby 2.2.3 with rbenv it has a different version

I'm trying to use Rails 5, which requires Ruby version >= 2.2.2.
I installed 2.2.3 with rbenv install 2.2.3 and set it global. When I check with ruby -v I get ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15].
However when I run bundle exec railties/exe/rails new /parent-folder/api --api --edge I get the error:
Rails 5 requires Ruby 2.2.2 or newer.
You're running
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin14.0]
If I explicitly set the local version to the exact version number 2.2.3p173 or 2.2.3 then it says rbenv: version '2.2.3' is not installed (or 2.2.3p173 accordingly).
When I perform rbenv install -l to check available versions only 2.2.3 is listed, not the 2.2.3p173.
Don't understand how to get this to work.
Side notes: I have updated ruby build, my $PATH has rbenv setup correctly, I don't have rvm installed.
Instead of bundle exec railties/exe/rails new /parent-folder/api --api --edge try ./rails/railties/exe/rails new myapp --edge --dev where 'rails' is the rails git repo.

Ruby -v gives me ruby 2.1.5...but rails server says I have version 2.0.0

Someones-iMac:john_sept_2013 Tony$ rails server
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.5
Someones-iMac:john_sept_2013 Tony$ ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]
So the console tells me I have ruby version 2.0.0 but ruby -v tells me I have a version of ruby 2.1.5.
Any ideas what is going wrong here?
Thanks in advance.
I suppouse something is wrong with the PATH variable.
If you use rvm try rvm use 2.1.5 or rbenv global 2.1.5 for rbenv and start rails again

Rails is not using my global Ruby version

I want to use Rails with Ruby 2.1.0, but it's using Ruby 1.9.3 (the system's version).
I'm using rbenv to manage my Ruby versions. My steps were something along the lines of:
$ rbenv install 2.1.0
$ rbenv global 2.1.0
$ sudo gem install rails -v 4.0.2
$ rbenv rehash
$ rbenv versions
system
* 2.1.0 (set by /home/dennis/.rbenv/version)
$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails new app && cd app
$ rails server
Rails is using is Ruby 1.9.3 (x86_64-linux), according to localhost:3000/rails/info/properties. A log message from rails server gives: INFO ruby 1.9.3 (2012-04-20) [x86_64-linux].
I think Rails is using the system version of Ruby because the versions match.
$ rbenv local system
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
$ rbenv local --unset # Unset local Ruby version, go back to 2.1.0
Some things I've tried with no luck:
setting the local and shell versions of Ruby to 2.1.0 with rbenv
rehash rbenv shims (rbenv says to do this after installing executables)
made new Rails projects after switching to 2.1.0 just in case I made the projects while using 1.9.3
putting 2.1.0 in a .ruby-version file in the root of my project (suggested by #Agis)
restarting terminal session and starting a login bash shell (suggested by #Russel)
specifying the desired Ruby version in the project's Gemfile (suggested by #rlecaro2)
FWIW, I'm using Ubuntu 13.10 with the fish shell.
Sounds silly, but did you restart terminal session?
Otherwise try and type
/bin/bash --login
You didn't tell how you installed rbenv, but I think it is per-user installation (which is default). In this case you should install gems without using sudo. When you did sudo gem install rails, it was installed in system ruby, not rbenv's selected one.
Solution - install rails without sudo:
rbenv global 2.1.0
gem install rails
rbenv rehash
Try creating a .ruby-version file in the root of your project with the following contents:
2.1.0

Resources