Search code examples
node.jslinuxnpmsh

Linux reboot the terminal for npm command function


I have a shell script where I am installing the npm using nvm. Since after my installation of nvm, it installs the npm using nvm install node -> nvm use <version>.

After this, I have npm cache clean, which cannot recognize the command npm. Since I know that, for getting the node to work in the terminal, we need to restart. But I have upcoming commands in the shell for which bash cannot stop, hence I get errors, because I am using npm to install other software tools.

Error is: npm command is not found.

Shell Script

# This is for the running the project
#!/bin/bash

# Install NodeJS using nvm
nvm install node
nvm install 11.12.0
nvm use 11.12.0

# Install Cordova and Ionic
npm cache clean
sudo npm install -g cordova@8.1.2 ionic

Is there anyway that I can continue the process without restarting terminal for command process?


Solution

  • Try call npm with help nvm exec npm

    nvm exec cache clean
    nvm exec npm install -g cordova@8.1.2 ionic
    

    Don't use sudo in script. Run your script with needed for running rights. Or run shell script with help sudo