2

我通过 SSH 登录到我的 Bluehost 服务器,我想安装 Ruby v1.9.3 和 Rails v3.2.13。Ruby 的默认版本似乎是 1.8.7,Rails 是 2.3.11。

我尝试使用以下方法升级 Rails:

gem install rails -v 3.2.13 --no-rdoc --no-ri

我得到以下输出:

Successfully installed rails-3.2.13
1 gem installed

然后我尝试运行检查它是否已安装:

rails -v

我得到以下输出:

Rails 2.3.11

这些是我在根文件夹中的 bash_profile 和 bashrc 文件:

bash_profile:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs



export PATH=$HOME/bin:$HOME/.gems/bin:$PATH
export GEM_HOME="$HOME/.gems"
export GEM_PATH="$HOME/.gems:/usr/lib64/ruby/gems/1.8"

unset USERNAME

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

.bashrc:

# .bashrc

# User specific aliases and functions
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'

export HPATH=$HOME
export GEM_HOME=$HPATH/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib64/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HPATH/ruby/gems/bin
export PATH=$PATH:$HPATH/ruby/gems

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting

为什么不升级?此外,我应该在 bluehost SSH 会话中使用什么命令来升级 Ruby?

4

2 回答 2

1

放入.bash_profile(在您的根目录中)下一行:

export PATH=$HOME/bin:$HOME/.gems/bin:$PATH
export GEM_HOME="$HOME/.gems"
export GEM_PATH="$HOME/.gems:/usr/lib/ruby/gems/1.8"

重新连接到您的帐户并尝试再次安装 rails。

更新

我在 Bluehost 上有一个帐户,我运行 Ruby 1.8.7 + Ruby on Rails 3.2.13。一些文件进入根目录:

.bashrc

# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
  . /etc/bashrc
fi

.bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
# User specific environment and startup programs
export PATH=$HOME/bin:$HOME/.gems/bin:$PATH

unset USERNAME

export GEM_HOME="$HOME/.gems"
export GEM_PATH="$HOME/.gems:/usr/lib/ruby/gems/1.8"

.gemrc

gemhome: /home2/myserv/.gems
gempath:
- /home2/myserv/.gems
- /usr/lib/ruby/gems/1.8
gem: --no-ri --no-rdoc

而不是/home2/myserv你应该提供从根目录到你的主目录的系统路径。

于 2013-09-12T17:40:10.407 回答
0

我向您推荐使用rvmphussion 乘客(pp) 的部署。在正常方法中,如果没有 pp,您必须为 .htaccess 中的每个 ruby​​ bin 提供路径。可行吗?是的,但必须在 .bashrc 处处理 rvm 路径...

使用 PP 更好的方法可以为您提取 ruby​​...在与 rvm 组合中,您可以拥有与 gemsets 一样多的 ruby​​-rails 版本。在此处查看说明。检查 rvm 以获取 gemsets 信息。注意,由于vps在Bluehost中共享/文件夹,所以将rvm安装在.rvm,而不是/usr/local/rvm/,否则你可能会发现权限问题。

但这还不足以在 Bluehost 上部署,因为您的服务器正在运行 WHM,这意味着您无法轻松更改 httpd.conf 文件。因此,如果您按照所有说明进行操作并且 Apache 没有显示您的 rails 应用程序,那么您就差两步了。

首先,在 www.yoursite.com:2087 打开 whm。转到服务配置/Apache 配置/包含编辑器/并在 Pre Main Include 下,编写:

Include /etc/httpd/conf.d/passenger.conf

如果 doc 存在并且模块也在调用,则 Apache 将重新启动。

其次,打开你的 /usr/local/apache/conf/httpd.conf 文件,不要碰它。转到您的 VirtualHost 并阅读说明。那些会说:

# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/std/2/yourusername/your.site.com/*.conf"

您必须在那个非常精确的位置创建文件夹和文件。直接写在你的 httpd.conf 文件上。您必须使用您按照 pp 说明编写但修剪它们的相同行。例如:

<VirtualHost *:80> // NO NEEDED
ServerName yourserver.com // NO NEEDED

# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/myapp/code/public

PassengerRuby /path-to-ruby

# Relax Apache security settings
<Directory /var/www/myapp/code/public>
  Allow from all
  Options -MultiViews
  # Uncomment this if you're on Apache >= 2.4:
  #Require all granted
</Directory>
</VirtualHost> // NO NEEDED

同样,您不需要 VirtualHost 或 ServerName,因为找到的文件就像在 httpd.conf 中的 VirtualHost 中写入一样。

最后,当使用 rvm 和 gemsets 时,在应用程序的根文件夹中写入几个文件是一种简单的做法,与 Gemfile 相同。你需要:

At .ruby-version write:
2.2.2 // just the numbers of your version

And at .ruby-gemset write:
my_gemset_name

这将确保在您的应用程序运行时自动调用正确的 ruby​​ bin。

于 2016-03-05T00:29:41.253 回答