rails -v errors when setting up rvm - ruby-on-rails

I am trying to set up an environment as per this tutorial http://railstutorial.org/book#sec:1.2.2.3 however I get the below error when running 'rails -v'
bash-3.2$ rails -v
/Users/sandbox1/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:762:in `report_activate_error': Could not find RubyGem rails (>= 0) (Gem::LoadError)
from /Users/sandbox1/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:219:in `activate'
from /Users/sandbox1/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb:1065:in `gem'
from /usr/bin/rails:18:in `<main>'
Has anyone had this before?

Incase anyone else has this problem and the marked answer doesn't solve it, here is what fixed it for me:
Don't use sudo.
"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...)"
Taken from here

resolved by running "rvm gemset update"

Related

RVM says it is using 2.7.3, but ubuntu says i am on 2.7.0

Using Ubuntu, I ran the command
rvm use 2.7.3
I then ran
sudo rake db:create
and was greeted by the error
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.3
Am I doing something wrong here? I have been battling with this for hours and have no idea how to proceed
The $PATH variable when using sudo is not the same as the $PATH for your non-sudo user. Because RVM works by modifying $PATH, the RVM modifications are lost when you invoke sudo. That's why RVM stops working with sudo.
If you really need to run something as root using RVM, then you can try it with rvmsudo instead.
You can read more here:
rvmsudo vs sudo?
Also check the manual for rvmsudo:
https://rvm.io/integration/sudo
However in your case it's better to adjust access to the database, so that root privileges are not needed for Rails to connect to the DB.

How to completely remove rvm from $PATH? Ruby gemfile specifity error

I know this is a very common question with hundreds of answers and guides however I believe my problem is unique.
After removing rvm and installing Rbenv I now get an error when running rails s or similar commands, the error reads Your Ruby version is 2.6.3, but your Gemfile specified 2.6.4
ruby -v = ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-darwin19]
rails -v = Your Ruby version is 2.6.3, but your Gemfile specified 2.6.4
my $PATH: /Users/EthanMorganClark/.rbenv/shims:/Users/JohnDoe/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/JohnDoe/.rvm/bin
Now I can see .rvm/bin is still there, and it shouldn't. This leads me to believe it could be the source of my ruby version problem.
My process:
I ran rvm implode and then gem uninstall rvm, then I went into .bashrc, .profile and .bash_profile and removed any traces of rvm. (I did the same with zsh, although I currently am using bash)
I also then ran this script found on the second answer, but in the end it also thinks anything rvm related it gone.
edit - I have also deleted the gemfile.lock, bundled and then get the same error.
Any suggestions, links or answers would be much appreciated. Thanks.
Your PATH will be used in-order, so having .rvm/bin at the end shouldn't really affect anything. That being said, figuring out how/where your PATH is modified can definitely be tough if you haven't been keeping your .bashrc/.zshrc/.bash_profile/.zlogin etc organized.
A high level list of things you should do:
find out what shell you're using, bash or zsh, etc
look in all your corresponding rc files for the respective shell for the culprit (try searching all .* files in ~)
use which -a ruby/which -a rails/etc to see which executable is invoked when you call it
check out this answer for a suggested way to manage your ruby & gem environment

Received odd RVM error in workspace, now rails commands aren't working

I just logged into my Ubuntu workspace on Cloud9. Upon logging in I saw an error.
RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does
that too, you can ignore these warnings with 'rvm rvmrc warning ignore
/home/ubuntu/workspace/Simutronix/Gemfile'. To ignore the warning for
all files run 'rvm rvmrc warning ignore allGemfiles'.
Which I've not seen before and wasn't occurring when I last used the workspace. I then attempted to run the Rails server.
rails server -b $IP -p $PORT
I got an error message back.
bash: rails: command not found
I then tried to run bundle install which also came back with command not found.
ruby -v returns ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux].
What's likely to have happened to cause this to happen in between logins and what can I do to fix it?
Looks like Ubuntu can't find your Rails installation. Make sure you have Rails installed on your workspace by typing:
rails -v
If it is properly installed, It should return something like
Rails 5.0.2
(depending upon your Rails version.)
If you don't have Rails installed, you can install it by typing
gem install rails
You can append --no-doc to the above command if you don't want it to install documentation, thereby speeding up the installation process (That's totally up to you, though. It won't affect your installation in any other way. I promise!)
If this doesn't solve your problem, please update your answer with your Gemfile.
Likely the Ruby version defined in your Gemfile and/or .ruby-version changed, which means you will have to install bundler and bundle the gems again. Running this should solve the issue:
gem install bundler
bundle install

Gem installed but 'command not found'

I've installed a Ruby gem called wordmove to work with pushing and pulling my Wordpress sites but when I run wordmove commands I get the error command not found. I've done some research and I haven't come up with much, I've come to the conclusion based on what I've seen that my Ruby install is messed up.
I ran echo "$PATH" from my root and it returned the following:
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/brettgolding/.rbenv/shims:/usr/local/bin:/user/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin
I am a noob with the terminal so have no idea how to clean this mess up.
So you're working with rbenv. According to its README, you should run rbenv rehash after installing any gems that have an executable command. Also, run it anytime you install a new Ruby version.

Restarting Rails for terminal session

I was doing the Ruby on Rails tutorial by Martl and closed my terminal on my Mac. I had reached Chapter 10 without a problem. When I opened another terminal nothing is working. When I run bundle install I get the following error message:
/Library/Ruby/Site/1.8/rubygems/dependency.rb:247:in to_specs': Could not find bundler (>= 0) amongst [rake-0.8.7, rake-0.8.7] (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems/dependency.rb:256:into_spec'
from /Library/Ruby/Site/1.8/rubygems.rb:1182:in `gem'
from /usr/bin/bundle:18
How do I get my terminal back to where it was?
Sounds like your RVM environment is not being loaded when you restart your terminal. The Ruby On Rails tutorial glosses over RVM installation rather quickly and thats why this step often gets missed.
Check out the RVM installation guide here in particular Section 2 which describes how to ensure the RVM commands go into your .bash_profile.
Let me know if you need further help.

Resources