Rails 4.2.0 load error on Ubuntu using rbenv - ruby-on-rails

I have installed multiple version of rails on my Ubuntu machine locally using Rbenv. Rails -v command works fine when I use it from some project. It shows the version like "2.3.8". But it shows error when I use Rails command from the main directory.
Rails -v or Rails new test_app:
Blockquote
/home/rashed/.rbenv/versions/2.2.1/bin/rails:23:in `load': cannot load such file -- /home/rashed/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/rails-4.2.0/bin/rails (LoadError)
from /home/rashed/.rbenv/versions/2.2.1/bin/rails:23:in
Blockquote
.
Gem shows these installed rails versions (4.2.0, 2.3.8, 2.3.4)
I am using ruby "2.2.1p85".

I also tried re-installing rails but it doesn't worked in this case. I tried this command
$ gem install railties && rbenv rehash
and this worked for me like charm

Related

Rails ignores ruby installed by rbenv

I am using ruby 2.7.6 for my project. On my laptop (KDE Neon) it was installed via rbenv and was working correctly.
After KDE was updated today I started getting
Your Ruby version is 3.0.2, but your Gemfile specified 2.7.6
To fix that I tried reinstalling both rbenv and ruby that comes with Ubuntu. Also tried rbenv rehash with no results. So far rbenv installs ruby correctly and correct vesion is displayed when I do ruby -v or bundle install in project folder but trying to run rails s gives me an error
Your Ruby version is 3.0.2, but your Gemfile specified 2.7.6
rbenv is installed into /home/some_user/.rbenv/
$PATH shows
bash: /home/some_user/.rbenv/shims:/home/some_user/.rbenv/shims:/home/some_user/.rbenv/bin:/home/some_user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin which I am not sure is correct.
You're not running the correct rails executable. Try prefixing your rails command with bundle exec, for example if you want to run the dev server, type bundle exec rails s instead of rails s.

Cannot install rails version 4.2.5 on Ubuntu in WSL when I have ruby 2.2.1 active. nokogiri requires Ruby version >= 2.3.0

Trying to install rails version 4.2.5 on Ubuntu in Windows Subsystem for Linux on Windows 10 when I have ruby 2.2.1 installed and active I get the following error:
~$ gem install rails -v 4.2.5
ERROR: Error installing rails:
nokogiri requires Ruby version >= 2.3.0.
I need these versions to collaborate on a project which uses these versions.
I started by installing WSL (1 not 2) on windows 10, then downloaded and installed Ubuntu Linux. Then I installed rbenv, updated dependencies, installed ruby 2.5.1 which was fairly easy.
I had problems installing ruby 2.2.1 but got there after doing
$ sudo apt-get install -y libssl1.0-dev
to install an earlier version of libssl which ruby 2.2.1 needs.
I installed node.js and an earlier version of bundler using
$ gem install bundler -v 1.17.3
as trying
$ gem install bundler
failed with a similar error.
(I also installed ruby 2.5.1 and rails 4.2.5 on top of it with few problems)
Trying various diagnostics showed rails was not installed for ruby 2.2.1
~$ rails
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.5.1
(but not in ruby 2.2.1, which is where I need it)
Looking at my files in windows File Explorer (only looking) I can see that while my ruby 2.5.1 gems include rails my ruby 2.2.1 files are incomplete and do not include rails.
I think the PATH is correct.
$ echo $PATH returns
/home/johnloughran/.rbenv/plugins/ruby- build/bin:/home/johnloughran/.rbenv/shims:/home/johnloughran/.rbenv/bin:/usr/
local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local
/games:/mnt/c/Program
Files/WindowsApps/CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2019.522.0_
x64__79rhkp1fndgsc: ........ :/snap/bin
I modified my .bashrc file to add various entries to the PATH which have been included above.
I repeated the whole process twice starting from scratch (uninstalling Ubuntu) with the same block at the end.
What is my best option here to try and continue?
Thanks Josien for your comments. In the first case my collaborators have these versions of Ruby and Rails working together, but its a few years now since they installed them. One, David, helped me by trying a fresh install of rails 4.2.5 on ruby 2.2.1 which ran into the same problem above with nokogiri.
He solved it by installing a lower version of nokogiri in a new test directory, which I repeated as:
test$ gem install nokogiri -v 1.9.1
This worked. Then I installed rails as
test$ gem install rails --version 4.2.5
At last .... it worked!!!! :-)
To prove it I was able to get rails to return its version correctly.
test$ rails -v
Rails 4.2.5
Then I was able to create an app as
<working-directory>$ rails new learn-ruby
which works, almost, having hit another dependency problem, but hey ... that's programming!
Re your second comment I do not know enough about this stuff to know how relevant it is that this version of ruby is deprecated and the rails version is getting there too.

difficulty installing and running rails (/usr/local/bin/rails: No such file or directory), having once reverted back to an early rails version

Error when doing rails new blah, after a project where I put rails back to an early version
rails was working fine, I could do rails new blah
I wanted to test changing rails versions for a project. My experience up until this point has been that changing the rails version of a project won't change rails globally! So my experience has been that when CDing out of a directory and doing rails -v I'm still on 5.2.2.1
So I made a project with the aim to push back to rails 0.8.0 (just as a test!)
~/rubymac/test16$ cat Gemfile | grep "^gem 'rails'"
gem 'rails', '0.8.0'
~/rubymac/test16$
and I did bundle update rails
and no error, and I saw in Gemfile.lock that rails 0.8.0 seems to be specified there so I guess that worked that far.
Then I did cd .. and did rails -v expecting to (still) see rails 5.2.2.1 which has been my experience in the past when I put a project back to a slightly earlier version of rails. But rails -v didn't work. And rails new blah123 didn't work either.
~/rubymac$ rails -v
(in /usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0)
rake aborted!
LoadError: cannot load such file -- rake/rdoctask
/usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0/Rakefile:3:in `<top (required)>'
/usr/local/lib/ruby/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
~/rubymac$
and
~/rubymac$ rails new blah2432
(in /usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0)
rake aborted!
LoadError: cannot load such file -- rake/rdoctask
/usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0/Rakefile:3:in `<top (required)>'
/usr/local/lib/ruby/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
~/rubymac$
So I searched and found this question new rails project error Rails 3. which suggested gem install rails -v3.0.9
So I did gem install rails -v5.2.2.1
and it gives no error
~/rubymac$ gem install rails -v5.2.2.1
Successfully installed rails-5.2.2.1
Parsing documentation for rails-5.2.2.1
Done installing documentation for rails after 0 seconds
1 gem installed
~/rubymac$
But rails -v still doesn't work
~/rubymac$ rails -v
(in /usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0)
rake aborted!
LoadError: cannot load such file -- rake/rdoctask
/usr/local/lib/ruby/gems/2.5.0/gems/rails-0.8.0/Rakefile:3:in `<top (required)>'
/usr/local/lib/ruby/gems/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
(See full trace by running task with --trace)
~/rubymac$
I do gem list and see what rails versions I have
~/rubymac$ gem list | grep "^rails ("
rails (5.2.2.1, 5.2.2, 5.2.1.1, 5.2.1, 5.2.0, 5.1.6, 5.1.4, 5.0.7.2, 5.0.7.1, 5.0.1, 5.0.0, 0.8.0)
~/rubymac$
I tried uninstalling rails 0.8.0. it also prompted me to remove the executable and I said yes
~/rubymac$ gem uninstall rails -v0.8.0
Remove executables:
rails
in addition to the gem? [Yn] y
Removing rails
Successfully uninstalled rails-0.8.0
~/rubymac$ gem list | grep "^rails ("
rails (5.2.2.1, 5.2.2, 5.2.1.1, 5.2.1, 5.2.0, 5.1.6, 5.1.4, 5.0.7.2, 5.0.7.1, 5.0.1, 5.0.0)
~/rubymac$ rails -v
-bash: /usr/local/bin/rails: No such file or directory
~/rubymac$ gem install rails -v5.2.2.1
Successfully installed rails-5.2.2.1
Parsing documentation for rails-5.2.2.1
Done installing documentation for rails after 0 seconds
1 gem installed
but maybe I went a step too far in saying yes to removing the executable earlier having been prompted because now I get '..rails: no such file or directory'
~/rubymac$ rails -v
-bash: /usr/local/bin/rails: No such file or directory
~/rubymac$
even after trying to install 5.2.2.1
~/rubymac$ gem install rails -v5.2.2.1
Successfully installed rails-5.2.2.1
Parsing documentation for rails-5.2.2.1
Done installing documentation for rails after 0 seconds
1 gem installed
~/rubymac$ rails -v
-bash: /usr/local/bin/rails: No such file or directory
~/rubymac$
Added
I then tried gem uninstall rails, I uninstalled all versions. I then did sudo gem install rails. I started a new terminal window. rails -v
when I do which rails it says /usr/bin/rails which is an improvement.
But when I do rails -v it says
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
~$
~$ gem list | grep rails
coffee-rails (4.2.2, 4.2.1)
jquery-rails (4.3.1, 4.1.1)
rails (5.2.2.1)
rails-controller-testing (0.1.1)
rails-dom-testing (2.0.3, 2.0.2)
rails-html-sanitizer (1.0.4, 1.0.3)
sass-rails (5.0.7, 5.0.6)
sprockets-rails (3.2.1, 3.2.0)
actually grep rail* is better 'cos includes railties as mentioned by Uninstall Rails completely
Also, I am not using any version control manager, no rvm or rbenv
First, try closing out of your terminal and restarting. Sometimes the PATH doesn't get updated with the rails executable after installation.
If that fails...
In your terminal run:
$ gem env
This should tell your where gems have been installed. Rails is, after all, just a gem. I use .rbenv as a Rails environment manager. This means my EXECUTABLE DIRECTORY is at: /Users/me/.rbenv/versions/2.5.1/bin Inside that folder I can do:
$ ls | grep rails
and I get:
drwxr-xr-x 3 me group 96 Mar 14 10:59 rails
Yay, Rails is installed and it does exist there. If you can find this, that means you have Rails installed, but your PATH cannot find it. PATH is an environment variable that usually contains a list of known directories that contain executable files. When I type rails -v, PATH gets checked. Lets make sure my PATH is working:
/Users/me/.rbenv/shims
Good. Don't worry about shims, all you need to know is that folder contains my rails executables. Yours should be the path to the EXECUTABLE DIRECTORY. Now add your executable dir to your PATH:
export PATH=PATH:/full/path/to/EXECUTABLE_DIRECTORY
That should be it. Try to run rails again. If that fails, try to manually run your rails executable. If that fails, your executable is broken or you're not looking at the right file (much more likely).
If you can't find the executable rails, then rails DNE somehow and you need to try to reinstall.
Okay, the solution was to uninstall rails completely, and then reinstall rails. But the problem I was running into was that it wasn't uninstalling rails completely.
In order to uninstall rails completely, it's mentioned here Uninstall Rails completely
You have to uninstall not just rails, but a gem called railties!
So, when you list rails gems, don't do | grep rails, do | grep rail (singular!). i.e. Do gem list | grep rail, then you get a list of rail related gems including railties.
I deleted/uninstalled all of those gems. (though possibly I only need to uninstall railties and rails).
So then I was in a position where the rails file(in osx that's /usr/bin/rails), was gone And, those gems were gone, which is fine.
(what I didn't want is either a)a position where the rails file is there and rails gives an error or b)the rails file is not there) So that was then fine in that it was uninstalled completely.
Then I did gem install rails, and it installed rails and related gems. And it was fine.

ruby on rails install help

So I run this command successfully: sudo gem install rails
It outputs: Successfully installed rails-3.0.10
However, whenever I type in rails -v it shows: Rails 1.2.6
How can this be? Whenever I create a new project and do rails server, localhost:3000 doesn't work.
It's likely that your system has rails preinstalled, and the rubygems version is not overriding it.
You might have luck installing rvm and then installing rails within an rvm gemset.

Error putting Instant Rails on Windows 7

I am trying to get my Instant Rails working on my Windows 7 laptop.
The error I keep getting when trying to access my site files are:
c:/rails/ruby/lib/site_ruby/1.8/rubygems.rb:779:in 'report_activate_error'
RubyGem version error: rack<1.1.0 not~> 1.0.1> <Gem::LoadError>
from c:/rails/ruby/lib/ruby.site_ruby/1.8/rubygems.rb:214:in 'activate'
from c:/rails/ruby/lib/ruby.site_ruby/1.8/rubygems.rb:1082:in 'gem'
from c:/depot/vendor/rails/actionpack/lib/action_controller.rb:34
from c://rails/ruby/lib/ruby.site_ruby/1.8/rubygems/custom_require.rb:31 in 'gem_original_require'
etc...
I have intalled Rubygems 1.3.7 and they work fine and when I run the test it works and the gem env shows that the 1.3.7 has been installed correctly.
What can I do to get this working?
Any prompt help would be VERY appreciated.
Thanks
Your rack gem is outdated. Try to run gem update rack. Or, if you use Rails with Bundler, just run bundle install in the root of your project and it will do everything for you.
I decided to write a little manual about the Ruby 1.8.7 and Rails stable installation.
Download RubyInstaller 1.8.7 from here. During the installation, check the 'Add Ruby executables to your PATH' box. After the installation, don't forget to restard cmd. Then try running ruby -v and gem -v to check for installed Ruby 1.8.7 and RubyGems 1.3.7;
Install the latest stable Rails 2.3.8 using gem install rails --no-ri --no-rdoc; Check it using rails -v;
Create a new application using rails myapp;
Test it: script/server. That's it!
gem install rack -v 1.0.1

Resources