2013-05-29 80 views
1

我试图写一个bash脚本,将安装rbenv从开始到结束bash脚本自动rbenv安装

但有没有工作主要是我改变了目录,但只在子shell出头。

#!/bin/bash 
echo "installing rbenv ruby manager manager" 
cd ~ 
git clone git://github.com/sstephenson/rbenv.git .rbenv 
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile 
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile 
source .bash_profile 

echo "installing ruby build for rbenv" 
git clone https://github.com/sstephenson/ruby-build.git 
cd ruby-build 
sudo ./install.sh 

echo "rbenv and ruby-build have been installed, installing ruby now.." 
sleep 2 

read -p "would you like chronospere to install ruby 1.9.3 [y/n]" RESP 
if [ "$RESP" = "y" ]; then 
    rbenv install 1.9.3-p327 
    rbenv rehash 
    rbenv global 1.9.3-p327 
    ruby -v 
else 
    echo "alrigt skipping.. vagrant has rbenv installed you can install ruby it at your leisure " 
    echo "hold cmd, and double clck https://github.com/sstephenson/rbenv for more info" 
fi 

cd ~ 

所以它好像安装它的工作。但我的大部分代码dosent得到运行,或没有得到运行的地方id喜欢它。

[email protected]:/vagrant$ ruby -v 
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux] 
[email protected]:/vagrant$ rbenv 
The program 'rbenv' is currently not installed. You can install it by typing: 
sudo apt-get install rbenv 

,你可以看到它,就好像什么也没有只安装了什么事是,source .bash_profile从来没有发生过

[email protected]:/vagrant$ cd  
[email protected]:~$ cd ~ 
[email protected]:~$ source .bash_profile 

后,我手动源的.bash_profile

[email protected]:~$ rbenv 
rbenv 0.4.0-45-g060f141 
[email protected]:~$ rbenv versions 
    * system (set by /home/vagrant/.rbenv/version) 
    1.9.3-p327 
[email protected]:~$ rbenv global 1.9.3-p327 
[email protected]:~$ ruby -v 
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux] 

所以你可以看到它的代码正在运行,而不是从一个目录移动到另一个目录。我甚至不知道这是否可能。我从〜/(HOME)移动到/ ruby​​-build回到〜然后到/ vagrant。这是可能的在一个单一的bash脚本。

回答

1

我也遇到过这个问题。对我来说关键是在curl调用之前添加export RBENV_ROOT="/home/vagrant/.rbenv"来抓取rbenv。这样的东西应该可以工作(用Ubuntu Precise 32位测试):

export RBENV_ROOT="/home/vagrant/.rbenv" 

curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash