![](/img/trans.png)
[英]How to use two ruby,rails version on same machine but different project?
[英]How to Run different Ruby versions and Rails version on same development machine
我有一台運行ruby 1.9.3p545
和Rails版本Rails 3.2.13
的開發機器,目前有5個帶有capistrano腳本的應用程序。
我現在想使用同一台機器但使用Ruby 2.0.0
和Rails 4.1
開發一個新的應用程序。
我該如何做到無沖突。 謝謝!
Rbenv: https : //github.com/sstephenson/rbenv
Ruby構建: https : //github.com/sstephenson/ruby-build
Rbenv安裝
作為根
cd /opt
git clone git://github.com/sstephenson/rbenv.git rbenv
touch /etc/profile.d/rbenv
echo 'export RBENV_ROOT=/opt/rbenv' >> /etc/profile.d/rbenv
echo 'export PATH=/opt/rbenv/bin:$PATH' >> /etc/profile.d/rbenv
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv
編輯/root/.bashrc並添加到文件的最頂部
source /etc/profile.d/rbenv
編輯/home/#your_user_name#/.bashrc並添加到文件的最頂部
source /etc/profile.d/rbenv
Ruby構建安裝
exec $SHELL
mkdir -p $RBENV_ROOT/plugins
cd $RBENV_ROOT/plugins
git clone git://github.com/sstephenson/ruby-build.git
echo 'export PATH="$RBENV_ROOT/plugins/ruby-build/bin:$PATH"' >> /etc/profile.d/rbenv
exec $SHELL
到那時,您已經准備就緒,可以安裝任何版本的ruby
Ruby安裝
版本2.1.2和1.9.3p545的示例,但是您可以選擇所需的任何版本
rbenv install 2.1.2
rbenv install 1.9.3p545
設置紅寶石的全球版本
rbenv global 2.1.2
設置Ruby的語言環境版本
cd /your/project/directory
rbenv local 1.9.3p545
安裝捆綁器
請注意,在從應用程序根目錄運行bundler來安裝gem之前,您必須使用以下命令自行安裝bundler
gem install --no-rdoc --no-ri bundler rake
rbenv rehash
更新rbenv
cd /opt/rbenv
git pull
cd /opt/rbenv/plugins/ruby-build
git pull
rbenv rehash
您可以查看這篇很棒的文章: Phusion Passenger和運行多個Ruby版本
基本上,您可以使用rvm和反向代理來完成它。 對於您的情況,ruby -v 2.0.0,如果您使用passenger,則可以:
在您的apache配置中設置反向代理
<VirtualHost *:80> ServerName www.hamburgers.com DocumentRoot /path/to/your/app/public PassengerEnabled off ProxyPass / http://127.0.0.1:3000 ProxyPassReverse / http://127.0.0.1:3000 </VirtualHost>
您也可以嘗試使用獨角獸代替乘客,或用ngix代替apache。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.