Cannot Find Module npm-cli.js Ubuntu


If you have run any node or npm related command on Ubuntu terminal, and at that time you are seeing “Cannot find module npm-cli.js error” on your terminal. So it means that you do not have npm-cli related module in your system or the path of npm module is not set in system environment variable, To fix this, you set the correct npm path in your system environment variables or uninstall it and reinstall.

Cannot Find Module npm-cli.js Linux Ubuntu

Here are the solutions to fix this error on Linux ubuntu system:

  • Solution 1: Set Node js System Path Environment Variables
  • Solution 2: Uninstall and Reinstall Node js

Solution 1: Set Node js System Path Environment Variables

To set the system path environment variable for Node.js via the command line on Ubuntu, follow these simple steps:


First find the path to wherever node and npm is installed in your system. For example /usr/bin/node and /usr/bin/npm for npm.

Now open the bash profile in the editor, for you can use this command:

nano ~/.bashrc

Now your bash profile file is opened, Now, you need to add export PATH=$PATH:/usr/bin/node and export PATH=$PATH:/usr/bin/npm at the end of the file:


export PATH=$PATH:/usr/bin/node
export PATH=$PATH:/usr/bin/npm

Save changes and exit the text editor. In Nano, you can do this by pressing Ctrl + X, then press Y to confirm the changes, and finally press Enter to exit.

To update any changes you made to the bash profile file, you can use:

source ~/.bashrc

Now you can open your terminal and type any command related to node or npm on the terminal and check that your error has been fixed.


If yes the error is still coming then you should use solution 2. The error will be completely removed.

Solution 2: Uninstall and Reinstall Node js

Type these commands on the terminal, which will completely remove npm from linux ubuntu system:

sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* ~/.npm
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/bin/node*
sudo rm -rf /usr/local/include/node*
sudo apt-get purge nodejs npm
sudo apt autoremove

Now to reinstall, you visit the link and download the latest tar.xz file.


Now type these commands on your terminal to start the installation process and install node and npm into Ubuntu:

tar -xf node-v#.#.#-linux-x64.tar.xz
sudo mv node-v#.#.#-linux-x64/bin/* /usr/local/bin/
sudo mv node-v#.#.#-linux-x64/lib/node_modules/ /usr/local/lib/

IMPORTANT NOTE:- You see the #.#.# in command. Whatever version you downloaded from the latest Ubuntu website. So you replace #.#.# with the downloaded node js version and then run the commands.


For example, you have downloaded version 20.x, then add something like this on commands:

tar -xf node-v20.0.0-linux-x64.tar.xz
sudo mv node-v20.0.0-linux-x64/bin/* /usr/local/bin/
sudo mv node-v20.0.0-linux-x64/lib/node_modules/ /usr/local/lib/

Here is the video guide to fix it:


That’s it; through this tutorial, you have resolved Cannot Find Module npm-cli.js Ubuntu.

Recommended Linux Ubuntu Tutorials


Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.


Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00