Skip to content

Instantly share code, notes, and snippets.

@snooc
Last active December 18, 2015 11:29
Show Gist options
  • Save snooc/5775881 to your computer and use it in GitHub Desktop.
Save snooc/5775881 to your computer and use it in GitHub Desktop.
Install systemwide rbenv and ruby on Ubuntu 13.04
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/passenger-4.0.5;
passenger_ruby /usr/local/rbenv/versions/2.0.0-p195/bin/ruby;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_min_length 512;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types text/css text/plain text/x-component application/javascript application/json application/xml application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
include /opt/nginx/conf/sites-enabled/*;
}
#
# This script assumes that ruby was installed using rbenv
#
# Run as root
# $ bash <(curl -s [GIST URL])
#
# Install passenger gem
printf "\n [ \033[00;34m..\033[0m ] Installing Passenger Gem\n\n"
gem install passenger
rbenv rehash
# Install Nginx
printf "\n [ \033[00;34m..\033[0m ] Running NGINX installer\n\n"
apt-get -y install libcurl4-openssl-dev
passenger-install-nginx-module
# Install nginx init.d script
printf "\n [ \033[00;34m..\033[0m ] Installing NGINX init.d script\n\n"
wget -O init-deb.sh https://library.linode.com/assets/1139-init-deb.sh
mv init-deb.sh /etc/init.d/nginx
chmod +x /etc/init.d/nginx
/usr/sbin/update-rc.d -f nginx defaults
service nginx restart
# Create Deploy user
printf "\n [ \033[00;34m..\033[0m ] Creating deploy user\n\n"
useradd -s /bin/bash -m deployer
passwd deployer
usermod -a -G sudo deployer
usermod -a -G staff deployer
usermod -a -G www-data deployer
# Create /var/www
printf "\n [ \033[00;34m..\033[0m ] Creating /var/www\n\n"
mkdir /var/www
chown deployer:www-data /var/www
apt-get install postgresql postgresql-client postgresql-server-dev-all libpq-dev
#
# WARNING: This script runs 'rm -rf' on most directories before installing. It will kill things.
# ...Also, it takes awhile to compile ruby on resource starved machines.
# (O_o *Looks at 512MB droplet*)
#
# Run as root
# $ bash <(curl -s [GIST URL])
#
# CONFIGURATION VAIRABLES
GLOBAL_RUBY_VERSION=${GLOBAL_RUBY_VERSION:-2.0.0-p195}
# Install needed packages
printf "\n [ \033[00;34m..\033[0m ] Updating System\n\n"
apt-get -y update
printf "\n [ \033[00;34m..\033[0m ] Upgrading System\n\n"
apt-get -y upgrade
printf "\n [ \033[00;34m..\033[0m ] Installing Needed Packages\n\n"
apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev \
libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev \
autoconf libc6-dev ncurses-dev automake libtool bison vim nodejs
# Install rbenv
printf "\n [ \033[00;34m..\033[0m ] Installing RBENV\n\n"
rm -rf /usr/local/rbenv
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
rm -f /usr/profile.d/rbenv.sh
echo '# rbenv setup' > /etc/profile.d/rbenv.sh
echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
chmod +x /etc/profile.d/rbenv.sh
source /etc/profile.d/rbenv.sh
# Install ruby-build
printf "\n [ \033[00;34m..\033[0m ] Installing RUBY-BUILD\n\n"
rm -rf /tmp/ruby-build
pushd /tmp
git clone git://github.com/sstephenson/ruby-build.git
cd ruby-build
./install.sh
popd
printf "\n [ \033[00;34m..\033[0m ] Installing Ruby $GLOBAL_RUBY_VERSION\n\n"
rbenv install $GLOBAL_RUBY_VERSION
rbenv global $GLOBAL_RUBY_VERSION
rbenv rehash
rm -f $HOME/.gemrc
echo "gem: --no-ri --no-rdoc" >> $HOME/.gemrc
# Update system gems and install bundler
printf "\n [ \033[00;34m..\033[0m ] Updating system gems and installing bundler\n\n"
gem update --system
gem install bundler
rbenv rehash
# Update RBENV and RUBY-BUILD permissions
printf "\n [ \033[00;34m..\033[0m ] Updating RBENV and RUBY-BUILD permissions\n\n"
chgrp -R staff /usr/local/rbenv
chgrp -R staff /usr/local/share/ruby-build
chmod g+rwxXs /usr/local/rbenv
chmod g+rwxXs /usr/local/share/ruby-build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment