What is the proper way to install Node.js with nvm?

I need Node.js for various reasons, like installed applications and also for web development projects. I also need multiple versions, which is why I use nvm.

My current setup works okay but seems to not work quite correctly.

I use the package manager (Add/Remove Software) and the nodejs package then gets installed as a dependency sometimes, which causes some issues (e.g. updates of electron apps via pacman/yay don’t work).
Node/npm are not up to date even though the installed package in the package manager says it is (i.e. npm -v shows different version than what’s installed according to the package manager)

The Arch Wiki mentions to add --assume-installed nodejs=<version>, but I cannot figure out how to use that as a setting for the Package manager. Do I need to add something to pacman.conf?

I need the older versions of node/npm mostly for web dev tasks. So it would be most convenient for me, if I can have node and npm installed via the package manager (therefore it will be kept up to date). And nvm uses normally the package manager installed version.
However, if there is a .nvmrc file in the project folder, nvm uses the version specified in there.
I get how the part with the .nvmrc file works. But what is a better way to have node installed on the system for applications?

This is what I did…

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

Thanks, I looked at that before.

Could you help me understand how that does handle the problem with installed dependency node differently?

I usually prefer installing software via the package manager, especially when there is a package in the official repo.

You are confusing “pamac/add or remove software” with “nvm”. NVM (Node Version Manager) handles different versions of node. You cannot use pamac/pacman to do that. Arch only supports the latest version of node available and so does Manjaro. So changing pacman.conf doesn’t matter.

Versions installed with nvm cannot be updated with pamac. See stackoverflow on how to properly update those.

Tl;dr - What you are trying to accomplish is not possible with pamac and there is a reason why tools like nvm exist. Install a node version with nvm and make use of .nvmrc. Also see Node.js - ArchWiki.

Sorry, maybe I was not clear in my question. I’m already using nvm and .nvmrc for years, and I read the section in the Arch wiki (I even linked it in the question.)

I use nvm (which I installed via pamac) and I have multiple versions of node on my system working.
But the nodejs package (in pamac) is not marked installed (and I guess not installed) since I never installed it with pamac.
If another package has nodejs as a dependency. I assume it will probably be installed since it’s not there yet (or am I wrong on this?), which messes things up. At least I ran into issues like that before. I am not sure what the exact culprit was or which package caused it, but it has a hassle to fix it.

For example, the Joplin package has nodejs as a dependency, and now I have nodejs-lts-gallium installed too.

Since I am currently doing a new installation of Manjaro, I would like to install node and nvm properly to avoid issues in the future.

In the Arch wiki is something mentioned but I don’t understand what to do with it.

If you decide to use nvmAUR, previously it was suggested to use nodejs-fake package from AUR. Which is now deleted. Suggested way is to use --assume-installed nodejs=<version>, as per the manual pacman(8) § TRANSACTION OPTIONS (APPLY TO -S, -R AND -U).

from ArchWiki node.js

So I guess I can break it down into 2 parts:

a) When I am using nvm, do I need to change anything in pamac, add a setting or whatnot so that pamac knows node is installed and does not install it again as dependency? Or should I install nodejs as well, even when nvm is installed?

b) A nice-to-have setup for me would be if the version of node that is used by other installed software (via pamac) uses a version of node that is kept up to date (via pamac if possible, or with nvm). For web dev I use a version of node that is needed for that project (installed with nvm and set with .nvmrc)

AFAIK most packages use the LTS releases as dependency. For example a have etcher installed which uses nodejs-lts-erbium as dependency. You can use pactree -r nodejs-lts-erbium to show packages that depend on the named package and pacman -Q | grep node to see all stuff installed via pamac. I don’t think any packages except ones from the AUR would conflict with those which you install with nvm.

Dependencies are updated automatically during a system update so no need to bother about that. The packages installed via nvm have to be manually updated.

That is a pacman flag that is recommended for your exact situation. When you are unable to install a package with pacman /pamac because that package depends on some other nodejs version, then add the flag with the version of node that you are using from nvm. Also see:

Ah okay, thank you.

So I should not install nodejs via pamac, when I am using nvm, because that could cause conflicts, but the LTS version used as dependencies should be fine.

The version of node that is used in the terminal (node -v), is the the version set with nvm.

The --assume-installed nodejs=<version> is something I would use after a installation via “add or remove software” GUI fails. But I have to do that via CLI, there is no setting in the GUI nor would it make sense to add it to pacman.conf?

Edit:
Thanks for link to that other topic, however it caused some confusion for me again :grimacing: :see_no_evil:

However, I’d recommend to use the nodejs package provided by the repository rather than the “manually installed” one if possible.

So should I install the pacman version for node parallel to the nvm version or not? I definitely need nvm for the older versions and easy version switching.

You should not mix your package managers. If you want to maintain node/nvm locally then stick to that and install everything node locally, including joplin.

Nope. This can be done with pacman only. Also this won’t work with pamac cli.

Maybe @moson can help further :slightly_smiling_face:

Hmm, I guess there is no elegant and clean solution then.

But thank you so much for your help! :blush: :pray: