尝试创建一个流浪者配置脚本,用于在 ubuntu 机器中安装 rails,如 https://gorails.com/setup/ubuntu/14.04
#!/bin/bash
pwd
apt-get update
apt-get -y install redis-server
apt-get -y install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone https://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
rbenv install 2.2.1
rbenv global 2.2.1
ruby -v
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
gem install rails -v 4.2.0
rbenv rehash
rails -v
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-common
sudo apt-get -y install postgresql-9.3 libpq-dev
脚本在exec $SHELL
时失败此外,Ruby版本不是2.2.1
,而是来自ubuntu ruby的默认版本1.9.3p484 (2013-11-22 revision 43786)
当你
执行一个新的 shell 时,你需要使用 here-doc 来获取脚本的其余部分作为输入传递:
#!/bin/bash
pwd
apt-get update
apt-get -y install redis-server
apt-get -y install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone https://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL <<EOF1
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL <<EOF2
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
rbenv install 2.2.1
rbenv global 2.2.1
ruby -v
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
gem install rails -v 4.2.0
rbenv rehash
rails -v
sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-common
sudo apt-get -y install postgresql-9.3 libpq-dev
EOF2
EOF1