Search code examples
terminalhomebrewn

Change n install location


I've got a macbook pro and I'm trying to setup my local environment. Because I develop websites that sometimes need different node version, I want to use "n" as node version management. I'm using brew.

I've downloaded "n" with brew, but this is creating a problem. "n" will install his node version in /usr/local/bin/node, but "n" uses /opt/homebrew/bin/node for his active node version:

Terminal n

How do I get "n" to install his node version in uses /opt/homebrew/bin/node so I can use those versions.


Solution

  • If n is not finding the correct binary, you can set the N_PREFIX environment variable to tell n where to look for Node.js binaries. Add the following to your shell configuration file (.bashrc, .zshrc, etc.) to set the N_PREFIX:

    export N_PREFIX="/usr/local"
    

    After adding this line, restart your terminal or run source ~/.bashrc (or the appropriate configuration file for your shell) to apply the changes.

    Now, when you install a new version of Node.js with n, it should be installed to the correct location, and n should be able to use it properly.