DEV Community

Cover image for How to install npm AKA Node.js package manager the right way on openSUSE Linux
Archer Allstars
Archer Allstars

Posted on

How to install npm AKA Node.js package manager the right way on openSUSE Linux

If you're a Node.js developer, you might be familiar with the npm install -g packagename command. However, if you run the command without sudo, you will likely face with the permission issue. This is due to your npm installation method.

In fact, you shouldn't use sudo with npm at all. See more about this here.


Installing npm the right way

First, if you installed npm via your repo's package manager, please uninstall it first!, either by using YaST Software Management and search for npm, or using this command:

sudo zypper remove npm
Enter fullscreen mode Exit fullscreen mode

Then, follow these steps:

  1. Install nvm with this install instruction. It's not only a node version manager, but also lets you use npm command without sudo.

    After running the curl or wget installation script, you will need to close the terminal window as the current terminal window doesn't know the nvm command yet.

  2. Run nvm install node to install the latest node(Node.js) along with the latest npm. It should return something like this:

    Downloading and installing node v20.0.0...
    Downloading https://nodejs.org/dist/v20.0.0/node-v20.0.0-linux-x64.tar.xz...
    ##################################################################################################### 100.0%
    Computing checksum with sha256sum
    Checksums matched!
    Now using node v20.0.0 (npm v9.6.4)
    Creating default alias: default -> node (-> v20.0.0)
    

    Note, the node installing via nvm will use its version by default, not the version on your system.

  3. If you want to update nvm, simply running the latest installation script on this page. You can monitor a new release of nvm version by watching their git as shown in the screenshot below:

    monitor a new version #1

    monitor a new version #2


I hope this helps, bye 💨


Cover Photo by GuerrillaBuzz on Unsplash

Top comments (6)

Collapse
 
tbroyer profile image
Thomas Broyer

You didn't really explain how that's better, and the implications.

My opinion: want something better than npm install -g? Just use npx.

That said, if you do want to use npm install -g for whatever reason, then no need to use nvm either: configure a prefix somewhere in your home directory for NPM to install to and add its node_modules to your NODE_PATH (and make sure to put its bin/ in your path).

And if you're using npm install -g to install Yarn or PNPM, consider using Corepack instead: nodejs.org/api/corepack.html

To me, using NVM really seems like cargocult.

Collapse
 
archerallstars profile image
Archer Allstars

Thanks for your suggestion ❤️

However, the reason I think this method is the best is due to its simplicity. I don't have to configure anything in my system. A command for installing nvm, and another command for installing both node and npm, are all I need to have a working environment.

Collapse
 
tbroyer profile image
Thomas Broyer

…but then you have (correct me if I'm wrong) to manually update Node and NPM (which means you have to follow the news about it), rather than simply relying on your system updates (assuming Linux here)

And with npx you have even fewer steps: none. 😉

Thread Thread
 
archerallstars profile image
Archer Allstars • Edited

…but then you have (correct me if I'm wrong) to manually update Node and NPM (which means you have to follow the news about it), rather than simply relying on your system updates (assuming Linux here)

To update npm, all you need to do is npm update -g like you would do without nvm. nvm is simply a node version manager that lets you develop on a specific node version easily (and without needing the root permission).

To update node, it's nvm install node.

And for development purposes (debugging and so on), it's even better to update the system and node version separately.

And with npx you have even fewer steps: none. 😉

I believe npm and npx have difference use cases.

Collapse
 
lauramrollins profile image
Laura M Rollins

To install npm (Node.js package manager) on openSUSE Linux, you can use the system's package manager, zypper. For more details Click here

Collapse
 
archerallstars profile image
Archer Allstars

As explained in the article, I am not recommended the installation with the package manager, as it would require root to run the command.

Nonetheless, I will report your post, as the link in your post is not related to the content here at all. Please, do your ads in the appropriate article/page/sub/etc.