markdown 通过Homebrew安装NVM,Node.js,Yarn

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 通过Homebrew安装NVM,Node.js,Yarn相关的知识,希望对你有一定的参考价值。

# Install NVM, NodeJS, Yarn via Homebrew

## Prerequisites
- [Homebrew](https://brew.sh/) should be installed (Command line tools for Xcode are included).

## Getting start

### Install NVM and NodeJS

1. Install `nvm` via Homebrew
    
    $ `brew install nvm`
    
2. Create system directory for nvm
    
    $ `mkdir ~/.nvm`
    
3. Add following line to your profile. (`.profile` or `.zshrc` or `.zprofile`)

    ```bash
      # NVM
      export NVM_DIR=~/.nvm
      source $(brew --prefix nvm)/nvm.sh
    ```
    
4. Close and open your terminal again.
  Or Choose one from the following command once for reload your profile. (`.profile` or `.zshrc` or `.zprofile`)
  
    Example
      - $ `source ~/.profile`
      - $ `source ~/.zshrc`
      - $ `source ~/.zprofile`
      
5. Verify `nvm` is installed

    $ `nvm -v`
    
6. Check all avaliable version by this command

    $ `nvm ls-remote`
    
7. Install NodeJS (_Recommended to install LTS version. Current LTS is 8.10.0_)
    
    $ `nvm install 8.10.0`
    
8. Check installed NodeJS in your machine.

    $ `nvm ls`
    
9. Set global nodejs version to environment.
    
    $ `nvm use default`
    
See more about `nvm` : https://github.com/creationix/nvm

### Install Yarn

1. Install `yarn` via Homebrew without `node` dependencies
    
    $ `brew install yarn --ignore-dependencies`
    
2. Checkout `node` in environment `$PATH` 

    $ `which node`
    
    It should be return => `/User/<your's-user-name>/.nvm/versions/node/8.10.0/bin/node`
    
3. Checkout `brew doctor` there should show message **WARNING missing yarn dependencies**
    
    $ `brew doctor`
    
4. Create symbol link from `nvm` for Homebrew

    $ `ln -s ~/.nvm/versions/node/ /usr/local/Cellar/`
    
    ** Note : If you installed multiple node versions via `nvm`. You should create symbol link by current global version. Following this commands **
    
    $ `nvm current` => v8.10.0
    
    $ `mkdir /usr/local/Cellar/node`
    
    $ `ln -s ~/.nvm/versions/node/8.10.0/ /usr/local/Cellar/node`
    
4. Checkout `brew doctor` again. There shouldn't have **WARNING** message.

    $ `brew doctor`

以上是关于markdown 通过Homebrew安装NVM,Node.js,Yarn的主要内容,如果未能解决你的问题,请参考以下文章

mac使用homebrew安装nvm

Mac机上安装nvm遇到的坑--nvm command not found

markdown 使用NVM安装Node.js.

markdown 如果你已经在Mac OS X或Linuxbrew上通过Homebrew安装了Node,那么如何修复npm的说明

markdown 使用nvm为Linux和macOS安装Node.js.

mac上管理不同node版本