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
website)
Part A: Install asdf-vm (A parts from official-
Install
asdf
via Homebrew. Currentasdf-vm
version is0.10.0
brew install asdf brew install gpg gawk # These are `asdf-nodejs` plugin dependencies
-
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
-
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
-
Verify
asdf
is installedasdf version
-
Install
asdf
pluginsasdf plugin add nodejs asdf plugin add yarn
-
Verify
asdf
andplugins
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
-
Install
nodejs
andyarn
Current LTS nodejs version is
16.14.x
, Codename:Gallium
asdf install nodejs lts asdf install yarn latest
-
Set
nodejs
andyarn
globally 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!
🥳 ❤️