Using rvm bundle install doesn't install rails - ruby-on-rails

I'm freshly using rvm for running a legacy project.
I installed rvm fine. Running which ruby gives the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Then running which bundle, also indicates that bundle is using the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Now to get my project running, I run bundle install. It's important to stress on the fact that in my Gemfile I have
gem 'rails', '5.0.7'
Running rails s after those steps, gives:
Rails is not currently installed on this system. To get the latest version, simply type:
Running which rails gives:
/usr/bin/rails
implying that the system version and not the rvm version is being used.
echo $PATH shows:
/Users/Mahmoud/.rvm/gems/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/gems/ruby-2.5.5#global/bin:/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/bin:/Users/Mahmoud/.pyenv/versions/3.7.2/bin:/usr/local/bin:/Users/Mahmoud/.pyenv/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/Mahmoud/.ebcli-virtual-env/executables:/usr/local/mysql/bin
My question is, why hasn't rails been installed when I used bundle install? And why is which rails refering to my system and not my rbenv path?

I'll bet your RVM isn't set up correctly and /usr/bin/ appears in your PATH before RVM's bin directory. Run echo $PATH to confirm.
If so, back up your dotfiles for safety and run rvm get head --auto and it should put your PATH right. Logout and log back in or source your dotfiles (source ~/.bash_profile or whatever) and try again.

Related

Rails - Closed terminal and rebooted machine - now bash tells me rails isn't installed

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails and made it about 1/2 way through yesterday. When I stopped for the day, I closed out iTerm2 and shut off the Macbook Pro. Today, I powered up, opened iTerm, navigated to my working directory (~/rubyonrails/learn-ruby) and entered rails -v.
I see this:
`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.`
So I run sudo gem install rails and it shows that it has installed rails-4.1.0. Now rails -v still gives me the same error message above.
I tried also running rvm use ruby-2.1.1#learn-rails first and I still get the error message.
So I'm a little stuck and I can't figure out what to do to get rails working. Also, how do I go about setting up the bash environment such that I don't have to go through this each time? It would be nice to nav to my working directory and just start work without having to do a bunch of re-installation and reconfiguration each time.
Regards,
Jeff
please type in your shell:
$ bash --login
and then repeat your commands.
rails -v
Also try to call it with the full path:
like:
/your/path/to/rails -v
I think that the shell just doesn't know where rvm/rails etc is located.
You can solve this by entering:
$ source ~/.rvm/scripts/rvm
When you switch to the ruby-2.1.1#learn-rails ruby/gemset combo, and do gem list, what do you see?
The way people usually use rvm is to have every project folder specify the ruby & gemset it uses (they don't all have to be different). This is done with files called .ruby-version and .ruby-gemset. These should contain, in your case, ruby-2.1.1 and learn-rails respectively.
Set these if you haven't already, then leave the folder and enter it again. Then do bundle install to install the gems for the project into the rvm/gemset combo.
Your problem is that you ran
sudo gem install rails
The error message telling you to do this comes from your system Ruby, which doesn't know that you want to use RVM.
RVM installs gems into your user-space directory. By using sudo, you're bypassing this and installing it into (effectively) the superuser space, i.e. globally.
If you instead just run
gem install rails
then you'll be using RVM's copy of the gem utility rather than the globally installed version.

Rails command Error

Im about to start work on another web application, I change directories to
/rails_projects
and enter
rails new blank
I then get this error
Error: Command not recognized
Usage: rails COMMAND [ARGS]
The common rails commands available for engines are:
generate Generate new code (short-cut alias: "g")
destroy Undo code generated with "generate" (short-cut alias: "d")
All commands can be run with -h for more information.
If you want to run any commands that need to be run in context
of the application, like `rails server` or `rails console`,
you should do it from application's directory (typically test/dummy).
I have reinstalled rails, and still same error, any ideas?
UPDATE:
It actually give me the same error when I type just
rails -h
rails
in cmd
For anyone with a similar error that may land here, this fixed it for me:
rake rails:update:bin
This will generate "new" versions of the binaries. Just say Yes when it inquires you to replace them.
I ran into a similar issue when trying to upgrade a Rails Engine from 3.2 to 4.1.
The culprit was the presence of script/rails which contained:
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/my_project/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
The problem line is there at the end: require 'rails/engine/commands. That was not allowing the full Rails CLI to load which omitted the new command. Removing that file solved my problem.
I'm pretty sure this wasn't the cause of your specific problem, but the symptoms were the same as mine and this was the first link in Google for the error message. Just passing along my findings to help anyone else that runs into this same situation.
It looks like the rails command believes it's inside of a rails engine, which is why a different set of commands are available to you. Notice the 'commands available for engines' text. New is not a command available for engines. I'm not sure why rails thinks the directory you're in is an engine, but likely your directory structure is mixed up somehow.
If anyone runs into this error and needs a last resort plan.
I ended up uninstalling rails, rvm, and installing a newer version of ruby and new gemset.
rvm implode
gem uninstall rails -v=4.0.2
gem uninstall railities
install rvm :
curl -L https://get.rvm.io | bash -s
rvm get stable
for mac:
brew install libtool libxslt libksba openssl
brew install libyaml
install ruby:
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/usr
if you have error
rvm install 2.0.0 --with-openssl-dir=$HOME/.rvm/opt/openssl
install new ruby gems from website. Unpackage it then go to folder and run
ruby setup.rb
gem update --system 2.1.9
install rails (you can choose your version)
gem install rails --version 4.0.2
gem install railties
I did this, and now system is working normal again.
Create another directory and run $ruby -v, check which version is available. Now run rails new app_name. Try once after closing the terminal and restarting.
This happen to me when a require error occurred in a gem (dependency) while loading.

Install rails from gem

I installed ruby and next rails as a gem with this command
gem install rails -include-dependencies
It installed successfully but even after restarting my command window i couldnt run commands like:
rails
or
rails s
My question is what do i have to add to my path so that rails is recognized in my command windwo?
----Update----
I ran gem list but rails isnt listed,
so i will reune the gem install rails command
If you are using rvm you need to use the gemset of RVM in which you have installed your rails gem.
cmd for the same is
rvm gemset list
will list the gemset persent in your version manager, later select the gemset with following command:
rvm gemset use [gemset_name]
hope am redirecting you in the right direction.
Try creating a project with:
rails new whatever
Go into the project:
cd whatever
Install dependencies:
bundle install
Start server:
rails s
If you use a unix based OS, you may need to get the path of the rails executable into your $PATH e.g. by e.g. exec $SHELL -l.
Apologies if you know about this already, but why don't you use a pre-packaged installer like RailsInstaller?
Are you using rbenv?
If so, try running this in your terminal:
rbenv rehash
Since you are using windows, you might not have added Ruby's bin directory in path :
To add path in windows :
Right click My Computer >> properties >> Adavced System Settings
Then edit the path variable in User Variable and just add the path of your installed Ruby's bin directory.
Open a new command prompt to get the path changes.

rbenv command line gems setup with system install

I am using the chef rbenv recipe (https://github.com/fnichol/chef-rbenv), doing a system wide install (goes into /usr/local/rbenv) with the rails lastmile cookbook (https://github.com/DanThiffault/rails-lastmile). The server works fine, I can install gems, but command line gems don't seem to work (valkyrie, mysql2psql).
Do I need to do additional work to get this working?
You have to run rbenv rehash everytime you install a gem with a command line script when using rbenv.
If you installed the gems in a bundle and are running the command from within the directory where the Gemfile is located, #riley's suggestion might be enough. Otherwise, rehash is the command that will make the executables available on the path.
I'm new to rbenv from rvm where it just seemed to work. It looks like in rbenv you have to run :
bundle exec gemxx
Or generate binstubs:
https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

Rails keeps telling me that it's not currently installed

I use rvm to manage different rubies and their gemsets. My shell is zsh with oh-my-zsh configured with basic settings. Enabled oh-my-zsh plugins are ruby, rails, osx, and git. Here's the command I used to install ruby-1.8.7 and rails-3.0.7.
rvm install 1.8.7
rvm use 1.8.7
gem install rails -v=3.0.7
and then I typed rails and got:
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.
I've tried more thorough installs also, Like reinstall rubygems after switching to ruby-1.8.7, or create a completely new gemset, but with no luck.
Here's the rvm info:
ruby-1.8.7-p352#rails:
system:
uname: "Darwin yicai.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
zsh: "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"
rvm:
version: "rvm 1.8.6 by Wayne E. Seguin (wayneeseguin#gmail.com) [https://rvm.beginrescueend.com/]"
ruby:
interpreter: "ruby"
version: "1.8.7"
date: "2011-06-30"
platform: "i686-darwin10.8.0"
patchlevel: "2011-06-30 patchlevel 352"
full_version: "ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin10.8.0]"
homes:
gem: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails"
ruby: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352"
binaries:
ruby: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/ruby"
irb: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/irb"
gem: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin/gem"
rake: "/Users/nil/.rvm/bin/rake"
environment:
PATH: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails/bin:/Users/nil/.rvm/gems/ruby-1.8.7-p352#global/bin:/Users/nil/.rvm/rubies/ruby-1.8.7-p352/bin:/Users/nil/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/sbin"
GEM_HOME: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails"
GEM_PATH: "/Users/nil/.rvm/gems/ruby-1.8.7-p352#rails:/Users/nil/.rvm/gems/ruby-1.8.7-p352#global"
MY_RUBY_HOME: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352"
IRBRC: "/Users/nil/.rvm/rubies/ruby-1.8.7-p352/.irbrc"
RUBYOPT: ""
gemset: "rails"
and the gem version is 1.8.10, the latest.
If you're running a rails command immediately after installing rails, you will need to restart your terminal before your commands will be recognized.
I had this problem today. Not completely related to your question, but since this page is what comes up in Google when I search for "Rails is not currently installed on this system", I thought I would add my answer:
What happened is that I was using ruby 1.9.2 with rails for a while, but then I needed to use ruby 1.8.7 to run some other script that I found.
Afterwards, I wanted to change by system back to using 1.9.2, and that's where the problem started:
$ rvm list
=> ruby-1.8.7-p352 [ x86_64 ]
ruby-1.9.2-p290 [ x86_64 ]
$ rvm use 1.9.2
I thought that would do the trick. But no, that gives me the "Rails is not currently installed on this system" message.
What I had forgotten is that I had configured rails using an rvm gemset. So I needed to specify the correct gemset when I was selecting which ruby version to make active.
$ rvm gemset list_all
gemsets for ruby-1.8.7-p352 (found in /Users/asgeo1/.rvm/gems/ruby-1.8.7-p352)
global
gemsets for ruby-1.9.2-p290 (found in /Users/asgeo1/.rvm/gems/ruby-1.9.2-p290)
global
rails31
$ rvm use ruby-1.9.2-p290#rails31
That did the trick.
Mac OS X, rbenv, and rails
I was getting the exact same issue but with rbenv rather than rvm. After verifying a correct .bash_profile.
.bash_profile
export PATH="$HOME/.rbenv/bin:/usr/local/bin:$PATH"
eval "$(rbenv init -)"
Restart the shell
exec $SHELL -l
Check the path
echo $PATH
Finally
I repeatedly installed and uninstalled rails but it was never placed in the .rbenv/bin directory after rbenv rehash. In the end I did a find . -name rails and uninstalled every gem that was returned and uninstalled rails. Then:
$ gem install rails
$ rbenv rehash
$ which rails
/Users/palmerc/.rbenv/shims/rails
I had the same issue and found that RVM was not showing as installed either if I tried the rvm command. All it took to fix both problems was running this command in the terminal
$ source ~/.rvm/scripts/rvm
Restart your terminal and then re-run your rails command
Rails is not reporting that it isn't installed. Your Debian system is telling you that rails isn't installed. One thing about rvm is that it relies on some complicated bash shell scripting and you sometimes need to start a fresh shell for changes to appear. You should also make sure that the correct rvm shell commands were added to your .zshrc file.
Also check your path to make sure the ~/.rvm/gems/... path in included.
I ran into this issue using rbenv. Turns out gem install rails did in fact install Rails but rails was not recognized as an executable. The fix for me was to run rbenv rehash.
I found this fix and more details on setting up Rails 5 at https://gorails.com/setup/osx/10.11-el-capitan
I have encountered this problem, but it has been resolved.
I use macOS, I do not use rvm, I only use HomeBrew, I first use gem env to get the installation directory of all gems, mine is:
$ gem env
RubyGems Environment:
   -RUBYGEMS VERSION: 3.1.2
   -RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin19]
   -INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
   -USER INSTALLATION DIRECTORY: /Users/myname/.gem/ruby/2.7.0
...
Then you try to go to /usr/local/lib/ruby/gems/2.7.0 to find the executable file directory of the rails gem that you have installed, for example: /usr/local/lib/ruby/gems/2.7.0/bin, then add to the path environment variable
I found this problem but the solutions above didn't solve it. I am not using rvm (and I'm working on mac) and I had to update the path to add rails executable directory:
echo 'export PATH="/usr/local/lib/ruby/gems/3.0.0/bin:$PATH"' >> ~/.zshrc
I had a similar issue, but with rbenv.
I originally installed ruby on bash. Then I played around with .bashrc in VIM, messed that file up, and reset it back to default. In doing so, I unknowingly removed the exported rbenv $PATH. Because of this, my terminal no longer recognized that I had ruby installed.
I revisited the ruby installation page (https://gorails.com/setup/ubuntu/15.04) and tried to set up my rbenv path again with this command:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
It failed.
Luckily, I had already switched to zsh (with oh-my-zsh) between the time I messed up my .bashrc and the time I tried to access irb from my terminal.
My solution was to set up the rbenv path per the installation guide, but by replacing all instances of .bashrc with .zshrc like so:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
Hope this helps!
Here's what I've done. And the problem is gone. Hence I guess problem solved.
rvm use system
change to the system ruby. remove all gems in it using the command provided and explained here. then I install wanted ruby versions from scratch:
rvm install 1.8.7
rvm install rails -v 3.0.7
then bundle install
for further detail, might need dig into the gem install procedure.
add source ~/.rvm/scripts/rvm to your .bashrc file if rails installs fine but then you get the error "rails is not currently installed". This frustrated me for a while but I found the answer here: http://www.codelearn.org/blog/how-to-install-ruby-rails-screencasts-linux-mac-windows
I just reloaded my terminal
source ~/.bashrc
See: How do I reload .bashrc without logging out and back in?
Rbenv users
I had the same issue and this worked for me.
Setting the ruby version in the current directory.
rbenv local 2.7.1
Then I was able to run rails new
I had the same problem but the solution above didn't help.
This was my scenario
rvm list
=> ree-1.8.7-2012.02 [ i686 ]
ruby-1.9.3-p125 [ x86_64 ]
which ruby
/Users/dev/.rvm/rubies/ree-1.8.7-2012.02/bin/ruby
which rails
/usr/bin/rails
gem list --local
..
rails (3.2.8)
rails2_asset_pipeline (0.1.20)
railties (3.2.8)
..
rvm use ruby-1.9.3-p125
which ruby
/Users/dev/.rvm/rubies/ruby-1.9.3-p125/bin/ruby
which rails
/Users/dev/.rvm/gems/ruby-1.9.3-p125/bin/rails
By uninstalling rails and railties and reinstalling rails when using ree my problem was resolved.
Hope this helps others in my situation, not sure how I got into it :S
I had the same problem, I ended up deleting my .rvmrc rvm --create --rvmrc 1.8.7#project where the 1.8.7#project is whatever you want your ruby to be. cded in and out and it worked. http://sirupsen.com/get-started-right-with-rvm/
Just had same problem and couldn't find an answer. Here's what I did:
find current rails path
$ which rails
returns something like this: /usr/local/rails
Delete current version:
$ sudo rm -rf /usr/local/rails
Reinstall rails
$ sudo gem install rails
I ran into this same issue and none of the answers given helped so I thought I'd share my solution in case it might be useful for someone else.
I was messing around with my .profile and .bashrc files and along the way I messed up my RVM install. Still not sure exactly what I did, but the fix was easy. Just had to run the following command, which cleans up all of your system path settings for RVM:
rvm get [head|stable] --auto-dotfiles
Note that if you're running an old version of RVM this may upgrade your setup, which may not be what you want.
A possible solution is to not maintain two different configuration files .bash_profile and .bashrc
The solution as suggested in this excellent post on the difference between .bash_profile and .bashrc is to source .bashrc from your .bash_profile file, then putting PATH and common settings in .bashrc.
Quoting,
add the following lines to .bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
end quote
I had this error after updating ruby. I had to run 'bundle install' to fix it.
Try to specify gemset explicitely in your Gemfile:
source 'https://rubygems.org'
ruby "2.2.3"
#ruby-gemset=rails424
Try This:
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use /bin/bash --login as the command.
$ bin/bash --login
$ rails -v
I had this message on my Mac:
Rails is not currently installed on this system. To get the latest
version, simply type:
and it was about the $PATH not being correct. The system has an outdated version of rails (/usr/bin/ruby). The path to your chosen version of ruby ($HOME/.rbenv/versions/2.3.0/bin) must precede the system's outdated version along $PATH var, like below:
export PATH="$HOME/.rbenv/versions/2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
adjust it to your version of ruby.
For MacOS (High Sierra):
Tokaido is the Rails installer system recommended on the "Getting Started" Rails guide page for Mac OS. But it doesn't just install, it runs its own shell scripts. If you start out using that, which sources its own shell environment, then later start a terminal without launching from the Tokaido shell, this happens, because the "rails" command falls back to the original system rails code on the Mac.
For mine, the 'which rails' command in a normal terminal returns
/usr/bin/rails
But after launching Tokaido's shell, 'which rails' gives this path:
/Users/charlesross/.tokaido/Gems/2.2.0/bin/rails
Out of nowhere Rails wasn't currently installed but, what fixed it was
rvm use ruby-2.6.0
...and verified my path in .bash_profile
export PATH="$PATH:$HOME/.rvm/bin"
I was having this problem today. I haven't 100% solved it, but in new tabs I can do rvm use 2.5.5 and then rails -v works fine.
➜ my-repo git:(next_release) ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
➜ my-repo git:(next_release) rails -v
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.
➜ my-repo git:(next_release) rvm use 2.5.5
Using /Users/amberwilkie/.rvm/gems/ruby-2.5.5
➜ my-repo git:(next_release) rails -v
Could not find rake-12.3.3 in any of the sources
Run `bundle install` to install missing gems.
➜ my-repo git:(next_release) bundle install
I was looking through the source and found another error message that suggested the user run the following command.
I ran the command and everything now works. None of the suggestions above worked for me. Run the command from inside your newly created Rails app.
gem pristine --all
Here is how it worked for me:
Intall rvm in mac by following the mac installation instruction
rvm install ruby
gem install rails
rails --version
For me ( MacOS Monterey, rbenv) adding rails version to gem install command get the problem resolved.
you can find a specific version of rails that matches to your ruby from this link and replace the VERSION .
gem install rails -v VERSION
rbenv rehash
after successful installation, then rails should be added to /Users/your_user/.rbenv/shims
Also plz check that your shims directory should be the first element of your path.
➜ ~ echo $PATH #
/Users/ario/.rbenv/shims: ...
I was following along with the Odin Project ruby-on-rails course by
installing rbenv,
adding eval "$(rbenv init -)" to ~/.zshrc
installing rails gem
attempting to run rails new my_first_rails_app
But I had forgot to run source ~/.zshrc after editing the file, so I was seeing the error:
Rails is not currently installed on this system.

Resources