Managing your Global Nx Installation

Nx can be ran in a total of 3 ways:

  • Through your package manager (e.g. npx nx, yarn nx, or pnpm exec nx)
  • Through an encapsulated install (e.g. ./nx or ./nx.bat)
  • Through a global Nx installation (e.g. nx)

With a global Nx installation, Nx looks for the local copy of Nx in your repo and hands off the process execution to it. This means that whichever version of Nx is installed locally in your repo is still the version of Nx that runs your code. For the most part, this can eliminate any issues that may arise from the global install being outdated.

However, there are still cases where an issue could arise. If the structure of your Nx workspace no longer matches up with what the globally installed copy of Nx expects, it may fail to hand off to your local installation properly and instead error. This commonly results in errors such as:

  • Could not find Nx modules in this workspace.
  • The current directory isn't part of an Nx workspace.

If you find yourself in this position, you will need to update your global install of Nx. Exactly how you do this will depend on which package manager you originally installed Nx with.

If you cannot remember which package manager you installed Nx globally with, the below commands should help narrow it down.

npm list --global nx

If you find Nx has been installed multiple times, you can remove the global installation for all but 1 package manager by running the following commands for the duplicate installations:

npm rm --global nx

Finally, to complete your global installation update, simply reinstall it with the package manager of your choosing:

npm install --global nx@latest