Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

rbenv,ruby-buildを使ってRails環境を構築するまで(Ubuntu)

More than 3 years have passed since last update.

しょっちゅうググり直してしまうので、自分用にまとめました。
rbenvは複数ユーザーで共有したいので、/usr/local/rbenv にインストールすることにします。

参考)
CentOSでrbenvをシステムにインストールする

install necessary packages

$ sudo apt-get -y install libssl-dev zlib1g-dev libreadline-dev libmysqlclient-dev sqlite3 libsqlite3-dev g++ git curl

install rbenv

$ cd /usr/local
$ sudo git clone git://github.com/sstephenson/rbenv.git rbenv

make export path setting

--no-rehash をつけないとログインのたび rehash するので遅くなるそうです。

/etc/profile.d/rbenv.sh
export RBENV_ROOT="/usr/local/rbenv"
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init --no-rehash -)"

load setting

$ source /etc/profile.d/rbenv.sh

confirm rbenv installed

$ type rbenv

install ruby-build

$ sudo git clone git://github.com/sstephenson/ruby-build.git rbenv/plugins/ruby-build

install Ruby

# rbenv install 2.3.1
# rbenv global 2.3.1

install bundler

# gem install bundler --no-ri --no-rdoc

install Rails

$ mkdir project
$ cd project
$ bundle init
Gemfile
source "https://rubygems.org"

gem "rails"

システムのgemにインストールせずにvendor/bundle以下に配置する

$ bundle install --path vendor/bundle
$ bundle exec rails new .

補足

bundle install で An error occurred while installing pg (0.17.1) というエラーが起きた時の対処

postgresqlとlibpgを入れることで解決できた

$ sudo apt-get install postgresql-9.3
$ sudo apt-get install libpq-dev
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away