How to start rails console on my ubuntu server

I am debugging an issue with a rails app on my ubuntu server and I am trying to start the rails console to run the 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 application is running and the gem is installed in this directory:

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

      

So how can I start the rails console?

+3


source to share


5 answers


bundle exec

for help:



$ bundle exec rails console

      

+6


source


I had the same problem. In my case, it has 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"

      

Loads rvm every time you load a new terminal session.

+1


source


First, let's find out how you installed Ruby: apt-get , rvm, or rbenv :

open a shell and type this

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

      

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

"xxx is a function" means what you set using the xxx method .

If both commands return "xxx: not found" then you installed using apt-get and you will need to reinstall using rbenv or rvm.

Now that you know which manager you were using, try to fix the problem.

If you installed using 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 terminal, reopen and try again "rails c"

PS: If none of this works, try installing another manager (if you are using RVM, try installing via RBENV and vice versa).

+1


source


looks like is rails

not in your path, so you will need to provide a path to it (and generally speaking, is .

not in your path in any * nix safe configured field)

try this in /var/www/myapp/current

RAILS_ENV=production ./bin/rails console 

      

This will give you a console using the version of rails that was installed in your kit, and you are in the correct environment.

+1


source


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

"bundle exec RAILS_TASK" as in this case "bundle exec rails s". When using bundler, it will find the executable in its GEM_PATH, which is set during ruby ​​install.

+1


source







All Articles