Skip to content

Instantly share code, notes, and snippets.

@Lumbe
Last active April 22, 2018 20:57
Show Gist options
  • Save Lumbe/bc6d4d34b3c03215b53cf3ee98ef9f62 to your computer and use it in GitHub Desktop.
Save Lumbe/bc6d4d34b3c03215b53cf3ee98ef9f62 to your computer and use it in GitHub Desktop.
New Rails 5.1 App on Cloud9 IDE (starter app guide)

Новое rails 5.1 приложение на c9.io (blank Ubuntu workspace)

1. Настройки RVM

$ rvm get stable --autolibs=enable            # upgrades to latest stable version
$ rvm list known                              # list all known ruby versions
$ rvm install 2.4.1                           # install latest ruby version
$ rvm use --default 2.4.1

2. Copy this to .bash_aliases on c9.io

3. Check and update Gem Manager

$ gem -v
2.6.12
$ gem update --system

4. RVM Gemsets

Not all Rails developers use RVM to manage gems, but many recommend it. Display a list of gemsets and See what gems are installed in the "global" gemset:

$ rvm gemset list
gemsets for ruby-2.4.1
=> (default)
   global

$ rvm gemset use global
$ gem list

To get a list of gems that are outdated:

$ gem outdated

To update all stale gems:

$ gem update

5. Faster Gem Installation

By default, when you install gems, documentation files will be installed. Developers seldom use gem documentation files (they’ll browse the web instead). Installing gem documentation files takes time, so many developers like to toggle the default so no documentation is installed.

Here’s how to speed up gem installation by disabling the documentation step:

$ printf "\ngem: --no-document" >> ~/.gemrc  

This adds the line gem: --no-document to the hidden .gemrc file in your home directory.

6. Install bundler

$ gem install bundler

7. Install Nokogiri

Nokogiri is a gem that is a dependency for many other gems. Nokogiri is a gem that requires compilation for your specific operating system. As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri. However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).

To save time, install the Nokogiri gem in the RVM global gemset:

$ gem install nokogiri

8. Install apt-transport-https (to avoid conflict when installing node.js and Yarn on c9.io)

First install apt-transport-https

$ sudo apt-get update
$ sudo apt-get install apt-transport-https

9. Update node.js version through NVM

List remote versions available for install

$ nvm ls-remote
...
v7.5.0
v7.6.0
v7.7.0
v7.7.1
v7.7.2
v7.7.3
v7.7.4
v7.8.0
v7.9.0
v7.10.0

Install latest stable version(v7.10.0 at the time)

$ nvm install stable

Check node.js version

$ node -v
v7.10.0

Set default node version on a shell

$ nvm alias default 7.10.0

10. Install Yarn package manager

$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
$ sudo apt-get update && sudo apt-get install yarn

11. Install Rails

Skip this step to save disk space quota on c9.io Check current Rails version. Rails 5.1.1 was current when this was written. Make a gemset just for the current stable release:

$ rvm use ruby-2.4.1@rails5.1 --create

and install rails:

$ gem install rails

Verify that the correct version of Rails is installed:

$ rails -v
Rails 5.1.1

12. New Rails Application


Here’s how to create a project-specific gemset, installing Rails,

$ mkdir myapp
$ cd myapp
$ rvm use ruby-2.4.1@myapp --ruby-version --create
$ gem install rails

and create a new application:

$ rails new .

Create application with webpack

$ rails new . --webpack

with react by default:

$ rails new . --webpack=react

with webpacker(react), postgresql database and without rails asset pipeline

$ rails new . --skip-sprockets --database=postgresql --webpack=react

We’ll name the new application "myapp." Obviously, you can give it any name you like.

With this workflow, you’ll first create a root directory for your application, then move into the new directory.

With one command you’ll create a new project-specific gemset. The option "—ruby-version" creates .ruby-version and .ruby-gemset files in the root directory. RVM recognizes these files in an application’s root directory and loads the required version of Ruby and the correct gemset whenever you enter the directory.

When we create the gemset, it will be empty (though it inherits use of all the gems in the global gemset). We immediately install Rails. The command gem install rails installs the most recent release of Rails.

Finally we run rails new .. We use the Unix "dot" convention to refer to the current directory. This assigns the name of the directory to the new application.

This approach is different from the way most beginners are taught to create a Rails application. Most instructions suggest using rails new myapp to generate a new application and then enter the directory to begin work. Our approach makes it easy to create a project-specific gemset and install Rails before the application is created.

The rails new command generates the default Rails starter app. If you wish, you can use the Rails Composer tool to generate a starter application with a choice of basic features and popular gems.

13. Quick Test


For a "smoke test" to see if everything runs, display a list of Rake tasks.

$ rake -T

There’s no need to run bundle exec rake instead of rake when you are using RVM (see RVM and bundler integration).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment