"File not found: lib" when switching to older rails version using RVM - ruby-on-rails

I currently have rails 3.0.3 and am trying to download and use version 3.0.1. I've downloaded and installed RVM and inputted the following code in Terminal (I have a Mac OS X 10.6.5):
rvm use 1.8.7
rvm gemset create rails3.0.1
rvm 1.8.7#rails3.0.1
sudo gem install rails --version=3.0.1
I use sudo gems because of the user permissions, or my lack there of. Anyway, after I enter the last line of code: "sudo gem install rails --version=3.0.1" I get the following error:
Successfully installed rails-3.0.1
1 gem installed
Installing ri documentation for rails-3.0.1...
File not found: lib
Not only can I apparently not able to switch versions of rails, even though it appears as though I have multiple versions installed, every time I try to check to see what version of rails I currently have I get the following result:
rails -v
/Library/Ruby/Site/1.8/rubygems.rb:779:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems.rb:214:in `activate'
from /Library/Ruby/Site/1.8/rubygems.rb:1082:in `gem'
from /usr/bin/rails:18
Also, I've already installed Rdoc and Xcode (I've done research and other suggestions pointed to installing both). I'm a RoR newbie, and especially an RVM newbie, so I would love an explanation and a solution to this madness.
Thank you for reading!

I think you went off the rails (ha-ha) right here:
sudo gem install rails --version=3.0.1
The RVM documentation has this to say about that:
DO NOT use sudo...
to work with RVM gems. When you do
sudo you are running commands as root,
another user in another shell and
hence all of the setup that RVM has
done for you is ignored while the
command runs under sudo (such things
as GEM_HOME, etc...). So to reiterate,
as soon as you 'sudo' you are running
as the root system user which will
clear out your environment as well as
any files it creates are not able to
be modified by your user and will
result in strange things happening.
(You will start to think that someone
has a voodoo doll of your
application...)

Related

What's the best way to run a RoR project on my localhost

I have a friend's website code, which is in Ruby on Rails.
I have tried to install RoR on my Mac using instructions at gorails.com
OS : Mac Mojave
ruby -v : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin18]
rails -v :
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem railties (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/rails:22:in `<main>'
What I tried : I installed ruby, and then rails, using gorails tutorial, and kept getting errors stating version number mismatch.
Keep in mind that creating a new app, worked, but trying to run this existing code is a problem.
So then I uninstalled everything and updated the version using rvm, and since then I am getting this error.
When I cd into the webapp folder and run bundle install, I get errors, such as:
zsh: /Users/abc/.rvm/gems/ruby-2.2.3#hs/bin/bundle: bad interpreter: /Users/abc/.rbenv/versions/2.5.3/bin/ruby: no such file or directory
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your
Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using
RVM are available at rvm.io/packages/openssl.
This project uses a PostgreSQL database, which I have setup already.
If required, I can share the gemfile of this project too.
What is the best way to get this project working?
Am I missing something crucial?
You can't run RVM and RBENV on the same machine. Pick one and remove the other. You're probably best to uninstall both and then pick one, start over.
Uninstall RBENV instructions here or in your case probably brew uninstall rbenv
Uninstall RVM see How can I remove RVM (Ruby Version Manager) from my system?
Close all terminals and then start a new one.
Install RVM see https://rvm.io/rvm/install
Then go to your project, make sure you have the correct ruby version needed by your project. If not, you will need to install with rvm install 2.5.1 for example.
Then run
rvm use 2.5.1 #or some other version
Then you should be able to run bundle install
The rest of the instructions in your link should be ok.

RVM and Bundler, byebug gem: C extensions are not supported

I have been using Ruby on Rails with postgresql and something suggested that I should install RVM which I did (I think it was to utilise Phonegap). Since I put RVM in place I have been unable to execute bundle install which in turn means that I can no longer run other rails commands.
Lots of reading hasn't really given me an answer but I have lots of ideas. Maybe someone can help focus those ideas into a solution?
When I run bundle install there are 3 gems that seem to be causing the problem, but I think they are interlinked. They are byebug 8.2.2 and pg 0.18.4 and binding_of caller 0.7.2
The contents of byebug-8.2.2/gem_make_out are as follows:
/home/damo/.rvm/rubies/jruby-9.0.5.0/bin/jruby -r ./siteconf20160927-16151-j7mhkf.rb extconf.rb
NotImplementedError: C extensions are not supported
<top> at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/mkmf.rb:1
require at org/jruby/RubyKernel.java:937
(root) at /home/damo/.rvm/rubies/jruby-9.0.5.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1
<top> at extconf.rb:6
extconf failed, exit code 1
When I look at byebug issues it simply says that byebug doesn't support jruby.
I did not have any issues before I installed RVM and I'm sure I read that byebug was hardwired into Rails 4. I wanted to tell you my Rails version but rails -v gives me a response of
Could not find proper version of railties (4.2.5) in any of the sources
Run `bundle install` to install missing gems.
Which seems to be my Catch 22!
This kinda sounds like you're not using RVM in a login shell. In Bash you can run bash -l, then source ~/.bashrc (or whatever contains your rvm invocation lines). After that, try rvm use ruby-2.2 (or whatever), and if you don't get "RVM is not a function" error, then you should be good to go.
Note that under RVM you'll probably have to do gem install bundler manually for each distinct ruby version (and gemset), because ruby (and gemsets) under RVM live in their own worlds, and system bundler tends to be old. If you're reusing ruby installations and either not using or sharing gemsets, bundler may already be up to date.
So: use a login shell, do rvm use <your_favorite_ruby_version>, install bundler if necessary, then bundle install.
Last but not least, I like to use .ruby-version files so I don't have to switch rubies and gemsets manually, and I can tell if everything's working from the output of rvm info.
Where you using jruby before you installed rvm? Seems like your default ruby changed to jruby as opposed to whatever you where using before (system ruby?).
Try running
rvm use system
in the root of your rails project then try the bundle install and see if that fixes it. If it does then then can use setup .ruby-version files to control which version of ruby you use per project.
Or else type
rvm use system --default
to set your default ruby back to the system one and continue like you where preciously.

"gem install rails" give FilePermissionError with rbenv on mac OS X

I've read all the other Stackoverflow posts on this problem but don't see any suitable solution for rbenv, so i'll post it on here. (most of the other posts suggest either using RVM, or the OP had already ran sudo gem install rails).
when i run gem install rails (without sudo), i get
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
is /Library/Ruby/Gems/2.0.0 the correct spot?
why am i getting this error? i'm on a fresh laptop that hasn't had much install.
i've got homebrew, rbenv, and ruby 2.0
rbenv should not be trying to install to your System install of Ruby. If you check the permissions on /Library/Ruby/Gems/2.0.0 you'll see it's owned by root, which means you'll need to sudo to write to it, which we're trying to avoid.
This suggests that either
There is something wrong with your rbenv installation, because it should be looking at /Users/whoami/.rbenv/versions/2.0.0. As you can see in their documentation. I'd confirm that your rbenv is operating correctly or maybe try reinstalling to make sure your rbenv installation of ruby is taking priority.
Your system ruby might be clobbering your rbenv. Have you made sure that your system ruby isn't taking precedence in your path? Try running gem list rake -d with a gem you already have installed to see where your gems are currently installed

Could not find RubyGem railties

I try to create new app with "rails new" command however getting this error:
'report_activate_error': Could not find RubyGem railties (>= 0) (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:244:in 'activate_dep'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:236:in `activate'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1307:in `gem'
from /usr/local/bin/rails:18
Any idea why?
by the way I am working on Ubuntu
gem list
*** LOCAL GEMS ***
it is empty but I installed rails just before
I have encountered the issue before.The solution is :
you must use comand gem install rails, not sudo gem install rails.
I encountered the same problem and found the following solution Here which was mentioned here. Hope it helps
After you installed RVM and after you set the default Ruby version in RVM, you need to re-install all ruby gems, e.g.
gem install rails
you need to install those gems as the user, not as root.
Because from now on RVM will keep track of all installed gems by the ruby version which was used to install them!
You need to install RVM (I don't know it is the best solution but it works) then use such rails commands like rvmsudo rails new or such. I use rails and ruby command with including rvm or rvmsudo phase and all of them start to work.
Do you have multiple Ruby installations on your system? Maybe you have installed some package (like Heroku with full installation) and you are using the 'new' Ruby installation. I have uninstalled the last Ruby and everything seems to be fine.
Edit: Not everything is fine... yet. Under Windows you will have to edit Heroku.bat (in your Program Files/Heroku path) and change the path to Ruby installation folder.
Install rvm and try it again to install rails
RVM provides a very great way to manage your gems in Gemsets
for multible ruby installations.
On the offizial rvm site is a installation tutorial
http://beginrescueend.com/

update to rails 3 on ubuntu

Hopefully this is an easy one - I'm trying to install rails on my netbook. I can#'t seem to get it to update to rails 3 (seems stuck on 2.3.5). Here's some terminal output to show you what I mean...
mike#Ubuntu-Netbook:~$ rails -v
Rails 2.3.5
mike#Ubuntu-Netbook:~$ gem update rails
Updating installed gems
Nothing to update
mike#Ubuntu-Netbook:~$ sudo gem install rails
[sudo] password for mike:
Successfully installed rails-3.1.0
1 gem installed
Installing ri documentation for rails-3.1.0...
file 'lib' not found
Installing RDoc documentation for rails-3.1.0...
file 'lib' not found
mike#Ubuntu-Netbook:~$ rails -v
Rails 2.3.5
See? Stuck at 2.3.5! I have done a whole bunch of rails installs on other machines and never had this problem before - what am I missing?
The 2.3.5 install is completely working.
EDIT: I did not get an answer to this question. I got around it by investigating rvm and installing that way instead.
Are you using bundler? Are you in an rvm gemset?
If you're using the latter, once you sudo, you're in a different user's rvm install, so installation won't be the same. If you're using bundler and have locked rails to 2.3.5, that's what it'll be regardless whether you run gem update or not.
If you can answer the above two questions, we can probably narrow down your issue.

Resources