Cannot Find Module npm-cli.js Ubuntu

In this tutorial, you will learn how to set the correct npm path in your system environment variables or uninstall it and reinstall it to fix that cannot find the module npm cli.js ubuntu.

Cannot Find Module npm-cli.js Linux Ubuntu

Here are the solutions to fix this error:

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 https://nodejs.org/en/download/ 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:

Conclusion

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

Recommended Linux Ubuntu Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *