How to create a rails new project without tainting the global rails environment.
Environment
OS
Linux ubuntu 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Ruby
1.9.3p545
Ruby on Rails
4.1.0
rbenv
rbenv 0.4.0-97-gfe0b243
Prerequisite
You must install bundler at least to your ruby environment.
1 2 | |
Steps
Create a working directory
Create a temporary directory for setup the rails environment. This enviroment will be deleted after committing and pushing to your repository.
1 2 | |
Create a ‘Gemfile’
Just only ‘rails’ in the ‘Gemfile’.
1 2 3 4 | |
Install Ruby on Ralis
Install the ruby on rails to vendor/bundle directory temporarily.
1
| |
Create a new rails project
<project> is a new rails project name.
Don’t forget to set --skip-bundle option, or all gems will be installed global location.
1
| |
Tidy some temporary files and directories
Delete all unnecessary files and directories.
1 2 3 | |
Setup the rails environment
Install gems depend on the Ruby on Rails. A new and official ‘Gemfile’ is created on bundle exec rails new <project> --skip-bundle.
1 2 | |
Check if the rails server starts successfully
Run rails server command and access to http://localhost:3000 with your browser.
1
| |
Update ‘.gitignore’
Add /vendor/bundle to .gitignore file.
1
| |