简体   繁体   English

如何在我的ubuntu服务器上启动rails控制台

[英]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: 我正在调试我的ubuntu服务器上的rails应用程序的问题,我正在尝试启动rails控制台来运行命令,但这是当我尝试启动控制台时会发生的情况:

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: Rails肯定安装,因为我的应用程序正在运行并且gem已安装在此目录中:

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

So how can i actually start the rails console? 那我怎么能真正启动rails控制台呢?

bundle exec到救援:

$ bundle exec rails console

I had this same issue once. 我有过同样的问题一次。 In my case it had to do with RVM. 就我而言,它与RVM有关。

Add this to your ~/.bashrc 将其添加到〜/ .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. 每次加载新的终端会话时,都会加载rvm。

First, let's discover how did you install Ruby: by apt-get , rvm or rbenv : 首先,让我们发现你是如何安装Ruby的:通过apt-getrvmrbenv

open a shell and type this 打开一个shell并输入它

# 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是函数”“-bash:type:xxx:not found” (其中“xxx”是“rbenv”或“rvm”)。

"xxx is a function" means that you had installed via xxx method. “xxx是一个函数”意味着您已经通过xxx方法安装。

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. 如果两个命令都返回“xxx:not found”,那么你已经通过apt-get安装了,你将需要通过rbenv或rvm重新安装。

Now that you know what manager you had use, let's try to fix the problem. 既然你知道你曾经使用过什么经理,让我们试着解决问题。

If you installed via RVM , try this: 如果您通过RVM安装,请尝试以下操作:

# \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: 如果您通过RBENV安装,请尝试以下方法:

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

Close the terminal, re-open and try again your "rails c" 关闭终端,重新打开并再次尝试“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). PS:如果没有任何效果,请尝试安装另一个管理器(如果您使用的是RVM,请尝试通过RBENV安装,反之亦然)。

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) 看起来像rails不在你的路径中,所以你需要指定它的路径(一般来说.在你的路径上没有任何明智配置的* nix框)

so try this in /var/www/myapp/current 所以在/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. 这应该会使用捆绑包中安装的rails版本为您提供一个控制台,让您进入正确的环境。

Better would be to use bundler when running rails specific command as 更好的方法是在运行rails特定命令时使用bundler

"bundle exec RAILS_TASK" like in these case "bundle exec rails s". “bundle exec RAILS_TASK”就像在这些情况下“捆绑exec rails s”。 When using bundler, it will find executable file in their GEM_PATH which is set during installation of ruby. 使用bundler时,它会在安装ruby期间设置的GEM_PATH中找到可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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