简体   繁体   中英

How to start rails console on my ubuntu server

I'm debugging an issue with a rails app on my ubuntu server and i'm trying to start the rails console to run a command, but this is what happens when I try to start the console:

myuser@rails-server1:/var/www/myapp/current$ rails c
The program 'rails' can be found in the following packages:
 * ruby-railties-3.2
 * ruby-railties-4.0
Try: sudo apt-get install <selected package>

Rails is definitely installed because my app is running and the gem is installed in this dir:

/var/www/myapp/shared/bundle/ruby/2.0.0/gems

So how can i actually start the rails console?

bundle exec到救援:

$ bundle exec rails console

I had this same issue once. In my case it had to do with RVM.

Add this to your ~/.bashrc

# This loads RVM into a shell session.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

This loads rvm each time you load a new terminal session.

First, let's discover how did you install Ruby: by apt-get , rvm or rbenv :

open a shell and type this

# type rbenv | head -1
# type rvm | head -1

each command will return a "xxx is a function" or a "-bash: type: xxx: not found" (where "xxx" is "rbenv" or "rvm").

"xxx is a function" means that you had installed via xxx method.

If both commands returns "xxx: not found", then you had installed via apt-get and you will need to re-install via rbenv or rvm.

Now that you know what manager you had use, let's try to fix the problem.

If you installed via RVM , try this:

# \curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles
# echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile

If you installed via RBENV , try this:

# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

Close the terminal, re-open and try again your "rails c"

PS: If nothing of this works, try to install another manager (if you are using RVM, try to install via RBENV, and vice-versa).

looks likes rails isn't in your path, so you will need to specify a path to it (and generally speaking . isn't in your path on any sanely configured *nix box)

so try this in /var/www/myapp/current

RAILS_ENV=production ./bin/rails console 

That should get you a console using the version of rails that was installed in your bundle and get you into the correct environment.

Better would be to use bundler when running rails specific command as

"bundle exec RAILS_TASK" like in these case "bundle exec rails s". When using bundler, it will find executable file in their GEM_PATH which is set during installation of ruby.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM