Skip to content

Instantly share code, notes, and snippets.

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

[DEPRECATED] Install NVM, NodeJS, Yarn via Homebrew

DEPRECATED WARNING

Dear all Github friends,

I moved this gist to the Github repository.

Following this repository https://github.com/nijicha/install_nodejs_and_yarn_homebrew

Thanks for star me 😃

HISTORY

Prerequisites

  • Homebrew should be installed (Command line tools for Xcode are included).

Getting start

Part A: 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

Part B: 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. Pick a choice which suitable for you.

    a. This is for those who installed only one version via nvm

    $ ln -s ~/.nvm/versions/node/ /usr/local/Cellar/

    b. 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 Global node 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

Riiiad 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

twentyfiffourteen 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

prinze77 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

twentyfiffourteen 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

nkshio 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

nijicha 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 !

@ASH-Michael

This comment has been minimized.

Copy link

ASH-Michael commented Jul 24, 2019

What is the purpose for creating the symbol link here? It's not really explained.

@joadr

This comment has been minimized.

Copy link

joadr commented Jul 26, 2019

What is the purpose for creating the symbol link here? It's not really explained.

remove the homebrew warning of missing dependencies

@WDever

This comment has been minimized.

Copy link

WDever commented Jul 29, 2019

I follow all of this gist. When Finally, I ran brew doctor, I can get

Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  node

So I ran brew link --overwrite node. And then the warning is removed.
Is this right way? I dont know

@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Jul 30, 2019

@WDever Oh sorry, You should not follow all of this Gist XD.

BTW. I edited this gist.

Following to
Part B > 4. > Pick a Choice

@TempD

This comment has been minimized.

Copy link

TempD commented Aug 13, 2019

Everything worked for me except the linking step that was supposed to clear out the missing dependency warning from brew doctor.

By executing this line: ln -s ~/.nvm/versions/node/v10.16.2/bin/node /usr/local/Cellar/node/ I was able to see it referenced correctly by yarn versions:

yarn versions v1.17.3
{ yarn:
   '1.17.3',
  http_parser:
   '2.8.0',
  node:
   '10.16.2',
  v8:
   '6.8.275.32-node.54',
  uv:
   '1.28.0',
  zlib:
   '1.2.11',
  brotli:
   '1.0.7',
  ares:
   '1.15.0',
  modules:
   '64',
  nghttp2:
   '1.34.0',
  napi:
   '4',
  openssl:
   '1.1.1c',
  icu:
   '64.2',
  unicode:
   '12.1',
  cldr:
   '35.1',
  tz:
   '2019a' }
✨  Done in 0.04s.

The warning is still there, but yarn works just fine! 🍺

@joekarasek

This comment has been minimized.

Copy link

joekarasek commented Aug 27, 2019

Thanks for the great guide. Something I look up every time I have to set up a new laptop.

One quick note/suggestion: I always seem to end up with issues down the road if I install yarn through homebrew, as it inevitably binds to a specific version of node, and when I switch between projects with different node versions I end up getting strange errors from yarn. The solution I found is to install yarn as a global dependency of node: npm install -g yarn.

You will need to repeat this for each version of node you are using.

@qasimalbaqali

This comment has been minimized.

Copy link

qasimalbaqali commented Sep 17, 2019

Thank you :)

@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Sep 23, 2019

Dear all Github friends,

I decided to move this gist to the Github repository.

Following this repository
https://github.com/nijicha/install_nodejs_and_yarn_homebrew

Thanks for star me 😃

@satishnani

This comment has been minimized.

Copy link

satishnani commented Nov 9, 2019

why can you do it as an automated script it will be more convenient and easy to use.

@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Nov 9, 2019

Hi @satishnani,

The automated script I would like to do it too. But I don't have a plan to do that for now. Lets me explain about this gist :)

This is a simple step (The step are outdated. Move to repo) for peoples who would like to install yarn and nvm and node with Homebrew. Just an option.
Anyway, there have many solutions to install your node.

And the purpose of starting to write down this gist. I just noted for my self
I had noted this gist for two years ago and I forgot about this.
One day I found many stargazers to this gist.
So I just answer their question who asked me in this thread.

BTW, I have a recommended automated script repository. Maybe you can check out here thoughtbot/laptop

@Edmund1645

This comment has been minimized.

Copy link

Edmund1645 commented Nov 30, 2019

Thanks a lot for this gist!!!..

I wanted to ask, is there an absolute need to install yarn?

@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Nov 30, 2019

Hi @Edmund1645

Answer is no, yarn is optional.

BTW, my opinion is yarn is suitable for me rather than npm

If you love npm Just install node via nvm then enjoy ❤️

Here is yarn usage that I loving it.

e.g.

yarn add *somethings* 😃
npm install --save *somethings* 🙈

Note: I moved this gist to the Github repository.

Following this repository better 😄
https://github.com/nijicha/install_nodejs_and_yarn_homebrew

@ziruihao

This comment has been minimized.

Copy link

ziruihao commented Dec 1, 2019

For linking yarn and node: ln -s ~/.nvm/versions/node/<latest-node-lts-version>/ /usr/local/Cellar/node, do we have to do this every time we change our node version?

@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Dec 2, 2019

@ziruihao,

Yes, Because This gist linking node from nvm alias as yarn Homebrew dependencies

@zmaleki

This comment has been minimized.

Copy link

zmaleki commented Jun 28, 2020

It's not clear how to add the nvm path to your profile. This worked for me:

Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)

 # NVM
  export NVM_DIR=~/.nvm
  source $(brew --prefix nvm)/nvm.sh
@nijicha

This comment has been minimized.

Copy link
Owner Author

nijicha commented Jun 29, 2020

@zmaleki

It's not clear how to add the nvm path to your profile. This worked for me:

Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)

 # NVM
  export NVM_DIR=~/.nvm
  source $(brew --prefix nvm)/nvm.sh

Thanks for your advice.

This depends on Unix user (Actually, I meant to Mac user) who uses the shell either bash / zsh / fish or others shell
You added those lines to ~/.bash_profile because you use the bash.

macOS Catalina changed the default shell to zsh
I had used zsh since macOS Mavericks

BTW
This gist is outdated.
This moved from the gist to the Github repository.
Try again at https://github.com/nijicha/install_nodejs_and_yarn_homebrew

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.