Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kappyh/b6802c6e78fbdcd615402bb04715e589 to your computer and use it in GitHub Desktop.
Save Kappyh/b6802c6e78fbdcd615402bb04715e589 to your computer and use it in GitHub Desktop.
GUIDE for mac OS X yarn nvm node install

GUIDE to install yarn, nvm (node) on macOS

last update: Jul 2019

Assumptions:

  • macOS >= 10.14 (Mojave)
  • homebrew properly installed

Prepare before setup (cleanup)

brew uninstall --force yarn node npm  # remove previously installed node, npm, yarn
brew cleanup  # clean all broken symlinks and "waste" (not really required as of homebrew 2019)
brew update  # always good to have the latest

Cleanup previously installed node/npm config

If you used the instructions provided in this gist, then you need to do some more cleanup:

  1. in ~/.bashrc:
# remove all the lines below:
export NPM_PACKAGES....
export NODE_PATH....
# and remove all references to these variables later in the file
  1. delete ".npmrc": rm -f ~/.npmrc

  2. delete all existing installed global npm packages (! but make sure to write down if you're using any of them, to reinstall afterwards)

# !!! DESTRUCTIVE COMMAND, PAY ATTENTION !!!
sudo rm -rf /usr/local/npm_packages   #  !!! MAKE SURE YOU COPY THIS LINE WITH FULL ABSOLUTE PATH COMPLETELY !!!

Install yarn via homebrew

# install Yarn w/o the node dependency
# https://github.com/yarnpkg/website/blob/13e95d80282f028ed7b28a822818ce128ea70b7e/lang/en/docs/_installations/mac.md
brew install yarn --ignore-dependencies  # the option --without-node doesn't seem to work anymore >= Feb 2019

Install nvm

Always consult the latest README (Install section)

Install nvm version 0.34.0 (current on Jul 2019)

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

Install node latest lts (dubnium, v10.x, current on Jul 2019)

nvm install lts/dubnium

Set nvm to use latest LTS as default for new bash sessions

echo "lts/dubnium" > .nvmrc #  default to the latest LTS version
nvm alias default lts/dubnium

RESTART all terminals => you're done ;-)

IMPORTANT NOTES

NEVER use sudo in any of the commands issued with node, yarn, or npm. If you need global packages installed, just follow nvm guidelines, and do yarn global add <package> or npm install -g <package>.

EXTRA: add fancy bash prompt to show ruby and node versions

...TODO... see .git-prompt-colors.sh

# This theme for gitprompt.sh is designed for dark color schemes
# it is clone of oh-my-zsh crunch theme style with exit status
override_git_prompt_colors() {
GIT_PROMPT_THEME_NAME="CrunchRC"
if [ -e ~/.rvm/bin/rvm-prompt ]; then
RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt v g)}'
else
if command -v rbenv > /dev/null; then
RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}'
fi
fi
NODE_PROMPT='{$(nvm current)}'
Time12a="\$(date +%H:%M)"
GIT_PROMPT_STAGED="${Yellow}● "
GIT_PROMPT_UNTRACKED="${Cyan}… "
GIT_PROMPT_STASHED="${BoldMagenta}⚑ "
GIT_PROMPT_CLEAN="${Green}✔ "
GIT_PROMPT_COMMAND_OK="${Green}✔ "
GIT_PROMPT_COMMAND_FAIL="${Red}✘ "
KERNEL_PROMPT='‹$(uname -r)›'
GIT_PROMPT_START_USER="${Magenta}rvm:${RUBY_PROMPT}; nvm:${NODE_PROMPT}\n_LAST_COMMAND_INDICATOR_${Cyan}${PathShort}${White}:"
GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"
GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}"
GIT_PROMPT_END_ROOT="${BoldRed} # ${ResetColor}"
GIT_PROMPT_LEADING_SPACE=0
GIT_PROMPT_PREFIX="${Green}["
GIT_PROMPT_SUFFIX="${Green}]"
GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭"
}
reload_git_prompt_colors "CrunchCustom"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment