install_nodejs_and_yarn_homebrew
install_nodejs_and_yarn_homebrew copied to clipboard
A step-by-step guideline to setup node bundle (node, npm, npx) and yarn via homebrew (managed by asdf-vm) on UNIX base machine
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)
-
Install
asdfvia Homebrew. Currentasdf-vmversion is0.10.0brew install asdf brew install gpg gawk # These are `asdf-nodejs` plugin dependencies -
Add following line to your profile. (
.profileor.zshrcor.zprofile)# asdf [ -s "/$(brew --prefix asdf)/libexec/asdf.sh" ] && . $(brew --prefix asdf)/libexec/asdf.sh -
Close and open your terminal again. Or Choose one from the following command once for reload your profile. (
.profileor.zshrcor.zprofile)Example
source ~/.profilesource ~/.zshrcsource ~/.zprofile
-
Verify
asdfis installedasdf version -
Install
asdfpluginsasdf plugin add nodejs asdf plugin add yarn -
Verify
asdfandpluginsare 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
homebrewon 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
v15or 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
-
Install
nodejsandyarnCurrent LTS nodejs version is
16.14.x, Codename:Galliumasdf install nodejs lts asdf install yarn latest -
Set
nodejsandyarnglobally for your machineasdf global nodejs lts asdf global yarn latest -
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 -
Enjoy! 🥳 ❤️
Read more
- https://asdf-vm.com
- https://github.com/asdf-vm/asdf-nodejs
- https://github.com/twuni/asdf-yarn