The installation of Ember CLI is essential to learning Ember and will be used throughout this book.
Before the installation of Ember CLI, we must have the Node Package Manager (npm) installed. npm
is a package manager for JavaScript and is installed by default with Node.js.
You must install version 0.12 or later of Node.js for Ember CLI to run. If you can, try to install version 4.0.0 or higher. This is the preferred version.
Node.js is available in several major platforms including Windows, Mac, and Linux. There are several ways to install Node.js:
This method is by far the easiest. To install node, you'll need to open the node website at http://nodejs.org/download. Click on the pkg
, msi
, or exe
installer for Windows or Mac. Run it after it's downloaded.
If you already have Homebrew installed, just run the following command:
$ brew install node
On the other hand, if you are running MacPorts, you can use the port install command:
$ sudo port install nodejs
MacPorts can be installed from http://www.macports.org. Homewbrew can be installed from http://brew.sh. Both offer simple package management for OS X systems.
A TAR file is a type of archive file. To install node via a TAR, you will need to download the TAR file from the Node.js website and extract and install it. One way of doing this is to use curl
.
I would only recommend this method if you are using a Linux distribution. If you are running on Linux, you'll need the right tools installed to compile from source. On Ubuntu, you'll need to install the build-essential and curl
packages:
$ curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1 $ ./configure $ sudo make install
All major Linux distributions offer Node.js packages. In Ubuntu, you can simply use apt-get
:
$ sudo apt-get install nodejs
In Fedora, you can use yum
:
$ yum install nodejs npm
Check with your Linux distribution to find out more details on how to install packages such as Node.js. Be aware that some distributions might offer outdated versions of Node.js. In this case, I would recommend that you use the Node Version Manager (NVM) installation method that will be discussed later.
To test your installation, run the –v
command:
$ node –v $ npm –v
This will show the current installed version. Keep in mind that you must run v0.12 or above to run Ember CLI. If possible, try to run v4.0.0 or above.
The NVM is a bash script that helps manage multiple active Node.js versions. NVM offers a very simple command-line interface to install any version of Node.js without having to visit the Node.js website. It separates each installation making it very easy to change between versions. I would recommend most beginners on Mac and Linux to run this. You can download NVM at https://github.com/creationix/nvm.
We'll need to use npm
to install Ember CLI. We'll install it globally with the –g
option so that it can be run anywhere from the command line.
$ sudo npm install –g ember-cli
If NVM was installed, you don't need sudo
at the start of the command.
$ sudo npm install –g bower
Similar to the last command, you don't need sudo
at the start of the command if Node.js was installed via NVM.
$ npm install –g phantomjs
$ npm install ember-cli-windows –g
$ ember-cli-windows
Working with Windows
Build times on Windows can be longer then Mac or Linux. The Ember CLI Windows tool can help speed up and optimize build performance. Just run it in the project directory. You can also download it as an add-on instead.
Another way to help with performance is to always run PowerShell/CMD with elevated privileges. Otherwise, performance issues and errors might occur. Lastly, try to use npm version 3 or higher. You may run into issues with long file paths with older versions in Windows.
Another handy tip is as follows:
Optional: Install Watchman
Watchman is a file-watching service for OS X and UNIX-like operating systems. It was developed by Facebook and is a more effective way for Ember CLI to watch project changes. If it's not installed, Ember CLI will fall back to using NodeWatcher. NodeWatcher is more error-prone and has trouble observing large trees. Install Watchman if your platform supports it. To download and configure Watchman, visit https://facebook.github.io/watchman/.
Ember CLI is written in Node.js and can be installed via npm. The tool interprets commands from the user to help create an Ember.js application. Each command from the user is looked up and then executed. Ember CLI relies on several other dependencies including Bower, Lodash, Broccoli, and Babel, to name a few.
Let's take a look at commands and aliases.
Once Ember CLI is installed, we'll have access to several commands. Here is a short list of some of the more important ones:
Command |
Purpose |
---|---|
|
This prints a list of available commands |
|
This creates a directory called |
|
This creates an application in the current directory |
|
This builds the application in the |
|
This starts a web server |
|
This runs a generator that builds scaffolding for the project |
|
This uninstalls the module that was created by the generator |
| |
|
This installs add-ons |
Keep in mind that for every command, there is an alias. These aliases make it a little quicker to run commands. Suppose that you wanted to build a new project. Normally, you would type this:
$ ember build
This will work and is fine. It will generate a new project and application structure. You can also use an alias.
$ ember b
Here is a list of some common aliases that you can use. This is optional.
Command |
Alias |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|