Code Monkey home page Code Monkey logo

install_nodejs_and_yarn_homebrew's Introduction

Install NodeJS, Yarn via Homebrew

Notice

Thank you everyone. For became a stargazers.

I had created this guideline for personal note purpose (first on Gist and then this repository)

Pull request is available. Please help me contribute this one 😂.

Legacy note (guideline) had moved to branch legacy-note

Prerequisites

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

Getting started

Part A: Install asdf-vm (A parts from official website)

  1. Install asdf via Homebrew. Current asdf-vm version is 0.10.0

    brew install asdf
    
    brew install gpg gawk # These are `asdf-nodejs` plugin dependencies
  2. Add following line to your profile. (.profile or .zshrc or .zprofile)

    # asdf
    [ -s "/$(brew --prefix asdf)/libexec/asdf.sh" ] && . $(brew --prefix asdf)/libexec/asdf.sh
  3. 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
  4. Verify asdf is installed

    asdf version

  5. Install asdf plugins

    asdf plugin add nodejs
    asdf plugin add yarn
  6. Verify asdf and plugins are ready!

    ❯ asdf list
    
    nodejs
    No versions installed
    yarn
    No versions installed

Part B: Install nodejs and yarn

NOTE

If you are matched to these condition below. You must install NodeJS v16+ (LTS Gallium)

  • Using Apple Silicon machine ✅
  • Installed homebrew on Native build (homebrew PATH: /opt/homebrew) ✅

Alternatively, If your had configured your SHELL to support Homebrew native & Homebrew rosetta2 (e.g. script below like I did) You can install v15 or lower via Homebrew rosetta2. But I prefer to use v16+ (LTS Gallium)

# My .zprofile

# Apple M1
if [ "$(uname -m)" = "arm64" ]; then
  # Use arm64 brew, with fallback to x86 brew
  if [ -f /opt/homebrew/bin/brew ]; then
    export PATH="/usr/local/bin${PATH+:$PATH}";
    eval $(/opt/homebrew/bin/brew shellenv)
  fi
else
  # Use x86 brew, with fallback to arm64 brew
  if [ -f /usr/local/bin/brew ]; then
    export PATH="/opt/homebrew/bin${PATH+:$PATH}";
    eval $(/usr/local/bin/brew shellenv)
  fi
fi
  1. Install nodejs and yarn

    Current LTS nodejs version is 16.14.x, Codename: Gallium

    asdf install nodejs lts
    asdf install yarn latest
  2. Set nodejs and yarn globally for your machine

    asdf global nodejs lts
    asdf global yarn latest
  3. Verify they are installed

    ❯ node -v
    v16.14.2
    
    ❯ npm -v
    8.5.0
    
    ❯ npx -v
    8.5.0
    
    ❯ yarn -v
    1.22.18
    
    ❯ asdf list
    nodejs
    16.14.2
    lts
    yarn
    1.22.18
    
    ❯ asdf current
    nodejs          lts             /Users/nijicha/.tool-versions
    yarn            1.22.18         /Users/nijicha/.tool-versions
  4. Enjoy! 🥳 ❤️

Read more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.