Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install NVM, Node.js, Yarn via Homebrew

Install NVM, NodeJS, Yarn via Homebrew

Prerequisites

  • Homebrew 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)

      # 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 --version

  6. Check all avaliable version by this command

    $ nvm ls-remote

  7. Install NodeJS (Recommended to install LTS version. Current LTS is Dubnium)

    $ nvm install --lts='Dubnium'

  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 and remove node dependencies from Homebrew

    $ brew install yarn

    $ brew uninstall node --ignore-dependencies

  2. Checkout node in environment $PATH

    $ which node

    It should be return => /User/<your's-user-name>/.nvm/versions/node/<latest-node-lts-version>/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 => v10.16.0 (Latest LTS: Dubnium) (This should be Current LTS version)

    $ mkdir /usr/local/Cellar/node

    $ ln -s ~/.nvm/versions/node/<latest-node-lts-version>/ /usr/local/Cellar/node

  5. Checkout brew doctor again. There shouldn't have WARNING message.

    $ brew doctor

@Riiiad

This comment has been minimized.

Copy link

commented Jun 17, 2019

Uninstalling all brew installed node version helps. As when you run ln -s ~/.nvm/versions/node/ /usr/local/Cellar/ it will tell you that it already exists.
So you should run brew uninstall --ignore-dependencies node and brew uninstall --force node to have a clean start.

@twentyfiffourteen

This comment has been minimized.

Copy link

commented Jun 18, 2019

Uninstalling all brew installed node version helps. As when you run ln -s ~/.nvm/versions/node/ /usr/local/Cellar/ it will tell you that it already exists.
So you should run brew uninstall --ignore-dependencies node and brew uninstall --force node to have a clean start.

Thanks !
This option --ignore-dependencies. No longer available.

@prinze77

This comment has been minimized.

Copy link

commented Jun 25, 2019

Uninstalling all brew installed node version helps. As when you run ln -s ~/.nvm/versions/node/ /usr/local/Cellar/ it will tell you that it already exists.
So you should run brew uninstall --ignore-dependencies node and brew uninstall --force node to have a clean start.

Thanks !
This option --ignore-dependencies. No longer available.

For me it worked

@twentyfiffourteen

This comment has been minimized.

Copy link

commented Jun 25, 2019

Uninstalling all brew installed node version helps. As when you run ln -s ~/.nvm/versions/node/ /usr/local/Cellar/ it will tell you that it already exists.
So you should run brew uninstall --ignore-dependencies node and brew uninstall --force node to have a clean start.

Thanks !
This option --ignore-dependencies. No longer available.

For me it worked

Oh sorry guys. I mean to this brew install yarn --ignore-dependencies is unsupported.

$ brew install yarn --ignore-dependencies

Warning: --ignore-dependencies is an unsupported Homebrew developer flag!
Adjust your PATH to put any preferred versions of applications earlier in the
PATH rather than using this unsupported flag!

==> Downloading https://yarnpkg.com/downloads/1.17.0/yarn-v1.17.0.tar.gz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/49970642/65c51280-8e9b-11e9-9a56-b8f4513cc801?X-Amz-Alg
######################################################################## 100.0%
 /usr/local/Cellar/yarn/1.17.0: 14 files, 5MB, built in 9 seconds
@nkshio

This comment has been minimized.

Copy link

commented Jul 16, 2019

Thanks for creating this awesome gist, live long :)

  1. Verify nvm is installed
    $ nvm -v

Correct way to check nvm version is nvm --version

@nijicha

This comment has been minimized.

Copy link
Owner Author

commented Jul 18, 2019

Thanks for creating this awesome gist, live long :)

  1. Verify nvm is installed
    $ nvm -v

Correct way to check nvm version is nvm --version

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.