Skip to content

Instantly share code, notes, and snippets.

@nijicha
Last active June 20, 2024 13:06
Show Gist options
  • Save nijicha/e5615548181676873118df79953cb709 to your computer and use it in GitHub Desktop.
Save nijicha/e5615548181676873118df79953cb709 to your computer and use it in GitHub Desktop.
Install NVM, Node.js, Yarn via Homebrew

[OUTDATED] Install NVM, NodeJS, Yarn via Homebrew

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

@nijicha
Copy link
Author

nijicha commented Dec 2, 2019

@ziruihao,

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

@zmaleki
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
Copy link
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