how to install npm
- User
how to install npm
- Assistant
how to install npm
To install npm (Node Package Manager), you typically install Node.js, as npm comes bundled with it. Here’s how you can install Node.js and npm on various operating systems:
Download the Installer:
Run the Installer:
Verify Installation:
node -v
npm -v
Using Homebrew (recommended):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install node
Verify Installation:
node -v
npm -v
Using the Node.js Installer:
Using a Package Manager:
sudo apt update
sudo apt install nodejs npm
sudo dnf install nodejs
sudo pacman -S nodejs npm
Using Node Version Manager (nvm): (This method is useful for managing multiple Node.js versions)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc or source ~/.zshrc):
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install node
node -v
npm -v
Once you have installed Node.js and npm, you can start using npm to manage your JavaScript packages. You can install global packages with:
npm install -g <package-name>
And for local project dependencies, create a package.json using:
npm init
This will guide you through creating a package.json file for your project.
That's it! You now have npm installed on your system.