Skip to content

Instantly share code, notes, and snippets.

@nijicha
Last active January 30, 2024 12:14
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 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
Copy link

Thanks a lot for this gist!!!..

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

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