+1

Creating an environment for Node.js on Mac

This is my memo for creating an environment for Node.js on Mac

Install flow

  1. Install Homebrew

  2. Install nodebrew

  3. Install Node.js

1. Homebrew

Homebrew is a package manager using for Mac

http://brew.sh/index.html

We need this to install nodebrew

Install Homebrew

・Confirm if the installation is completed?

$ brew -v

If a version is displayed after running the above command, the installation is completed

Homebrew 1.1.0
Homebrew/homebrew-core (git revision bb24; last commit 2016-11-15)

・Install

Run the script at http://brew.sh/index.html

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

※ THe current time is 2016/11/15

nodebrew

This is a tool for managing version of node.js

This tool can do multiple things with node.js such as switching between node.js' versions

・Confirm if the installation is completed? $ brew -v

If a version is displayed after running the above command, the installation is completed

nodebrew 0.9.6

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (compile from source)
    nodebrew install-binary <version>     Download and install <version> (binary file)
    nodebrew uninstall <version>          Uninstall <version>
    nodebrew use <version>                Use <version>
    nodebrew list                         List installed versions
    nodebrew ls                           Alias for `list`
    nodebrew ls-remote                    List remote versions
    nodebrew ls-all                       List remote and installed versions
    nodebrew alias <key> <value>          Set alias
    nodebrew unalias <key>                Remove alias
    nodebrew clean <version> | all        Remove source file
    nodebrew selfupdate                   Update nodebrew
    nodebrew migrate-package <version>    Install global NPM packages contained in <version> to current version
    nodebrew exec <version> -- <command>  Execute <command> using specified <version>

Example:
    # install from binary
    nodebrew install-binary v0.10.22

    # use a specific version number
    nodebrew use v0.10.22

    # io.js
    nodebrew install-binary io@v1.0.0
    nodebrew use io@v1.0.0

・Pass through environmental path

$ echo 'export PATH=$PATH:$HOME/.nodebrew/current/bin' >> ~/.bash_profile

If you use bash, it will be added to the appropriate place of each shell.

After adding, the terminal will be restarted

・Display version that can be installed

$ nodebrew ls-remote

When you run the above command, the version that can be installed will be displayed

v0.0.1    v0.0.2    v0.0.3    v0.0.4    v0.0.5    v0.0.6

〜Shortened〜

v7.0.0    v7.1.0

io@v1.0.0 io@v1.0.1 io@v1.0.2 io@v1.0.3 io@v1.0.4 io@v1.1.0 io@v1.2.0 io@v1.3.0
io@v1.4.1 io@v1.4.2 io@v1.4.3 io@v1.5.0 io@v1.5.1 io@v1.6.0 io@v1.6.1 io@v1.6.2
io@v1.6.3 io@v1.6.4 io@v1.7.1 io@v1.8.1 io@v1.8.2 io@v1.8.3 io@v1.8.4

io@v2.0.0 io@v2.0.1 io@v2.0.2 io@v2.1.0 io@v2.2.0 io@v2.2.1 io@v2.3.0 io@v2.3.1
io@v2.3.2 io@v2.3.3 io@v2.3.4 io@v2.4.0 io@v2.5.0

io@v3.0.0 io@v3.1.0 io@v3.2.0 io@v3.3.0 io@v3.3.1

・Install

$ nodebrew install-binary {version}

Choose and install the necesssary version When retrieving the latest version:

$ nodebrew install-binary latest

Enable the installed node

$ nodebrew ls

With this, we can list all the version that installed by command

v7.1.0

current: none

Because right after installing it becomes current: none so we have to enable the necessary version

$ nodebrew use v7.1.0

Confirm the version of node

$ node -v

All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí