Nx Development Setup Guide (Mac)
June 28, 2023 ยท View on GitHub
Clean installation steps for the whole setup of node/npm/nvm/nx, assuming mac with zsh shell.
Recommendations:
- Remove any pre-existing installations of node/npm/nvm/nx for a clean setup
- This guide recommends use of
nvmto enable management of node versions which allows much easier switching between different node versions if you work across different projects with different dependencies
1. Install antigen
source $(brew --prefix)/share/antigen/antigen.zsh
- Restart your shell/terminal
- If you get 'Antigen: Another process in running.' on shell startup just try closing & restarting your terminal/shell
2. Install nvm using the zsh-nvm plugin
- Use the excellent zsh-nvm plugin for nvm to make life easier (do not install
nvmusing brew) - Add the following to your
~/.zshrcfile:
export NVM_DIR="$HOME/.nvm"
antigen bundle lukechilds/zsh-nvm
antigen apply
- Add any extra
zsh-nvmoptions to your~/.zshrcfile, such as:
export NVM_LAZY_LOAD=true
export NVM_AUTO_USE=true
- The finished
~/.zshrcfile looks something like this:
source $(brew --prefix)/share/antigen/antigen.zsh
export NVM_DIR="$HOME/.nvm"
export NVM_LAZY_LOAD=true
export NVM_AUTO_USE=true
antigen bundle lukechilds/zsh-nvm
antigen apply
- Restart your shell/terminal and verify installation using the
nvm --version - Upgrade
nvmusingnvm upgrade
3. Install node
nvm install <nodeversion>eg.nvm install 19.1.0- This will install node and a compatible version of
npm/npxto~/.nvm/versions/node/19.1.0/... echo $pathshould now show~/.nvm/versions/node/19.1.0/binnode,npmandnpxshould now be accessible from the terminal/shell prompt
4. Installing multiple node versions (optional)
- Multiple node versions can be installed with
nvm install x.y.z nvm install nodewill install the latest version- Switch between node versions using
nvm use <version> - If your project requires a specific node version, add a
.nvmrcfile to the root of your project containing the text version required - Remember that
npmpackages installed with-gare installed to the currently selectednodeversion only, if you switch version, you may have to reinstall a global package for that version nvm listwill show all installed versionsnvm currentwill show the currently selected versionnvm default <version>will select a version that you like to be the default when you runnvm use default
5. Install nx
- Select the node version you want to install
nxto:nvm use <version> npm i -g nx- The previous command ensures that
nxcommand line can be run withoutnpx - Not sure when this became a thing, nor sure if the nx cli is still required as a global install, but it works.
nxshould now be accessible from the terminal/shell prompt
6. Visual Studio Code
Recommended extensions for Nx development: