Skip to content

Instantly share code, notes, and snippets.

@jayendra13
Created October 11, 2022 16:34
Show Gist options
  • Save jayendra13/ccbee01b7dd3c5b757d31ea8c86bc8ac to your computer and use it in GitHub Desktop.
Save jayendra13/ccbee01b7dd3c5b757d31ea8c86bc8ac to your computer and use it in GitHub Desktop.

Since the nix store is immutable and cannot be modified, you need to define a writable location for NPM packages to be installed globally.

Install NodeJS if you haven’t already.

Add the following to your ~/.npmrc to have it put the packages in the ~/.npm-packages folder:

prefix = ${HOME}/.npm-packages

You need to add the npm bin folder to your PATH in your shell’s rc file (i.e. .bashrc or .zshrc for example, so you can access the executables:

export PATH=~/.npm-packages/bin:$PATH

You also need to add the NODE_PATH to the same file:

export NODE_PATH=~/.npm-packages/lib/node_modules

Doing a source ./zshrc will allow you to not have to reload your terminal session (assuming you are using zsh for your shell, change to whatever you are using).

ref: https://matthewrhone.dev/nixos-npm-globally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment