我正在尝试编写一个将从头到尾安装rbenv的bash脚本
但是有些东西不起作用主要是我正在更改目录但仅在子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 ~
所以好像安装它有效。但是我的大部分代码都在运行,或者没有像它那样在地方ID中运行。
vagrant@precise64:/vagrant$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
vagrant@precise64:/vagrant$ rbenv
The program 'rbenv' is currently not installed. You can install it by typing:
sudo apt-get install rbenv
你可以看到它好像什么也没有安装只发生了source .bash_profile
从未发生过
vagrant@precise64:/vagrant$ cd
vagrant@precise64:~$ cd ~
vagrant@precise64:~$ source .bash_profile
手动输入bash_profile后
vagrant@precise64:~$ rbenv
rbenv 0.4.0-45-g060f141
vagrant@precise64:~$ rbenv versions
* system (set by /home/vagrant/.rbenv/version)
1.9.3-p327
vagrant@precise64:~$ rbenv global 1.9.3-p327
vagrant@precise64:~$ ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-linux]
因此您可以看到它好像代码正在运行而不是从一个目录移动到下一个目录。我甚至不知道这是否可行。我从〜/(HOME)移动到/ ruby-build回到〜然后到/ vagrant。这可以在一个bash脚本中实现。
答案 0 :(得分: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