Follow these steps to install Node.js (which includes npm) and the TypeScript compiler on macOS.
Method 1: Using the Official Installer
-
Download Node.js:
- Go to the official Node.js website: https://nodejs.org/
- Download the LTS (Long-Term Support) version.
- Command to open the website (optional, run in Terminal):
open [https://nodejs.org/](https://nodejs.org/)
-
Install Node.js:
- Run the downloaded
.pkg
installer and follow the on-screen instructions.
- Run the downloaded
-
Verify Node.js and npm Installation:
-
Open Terminal (search for "Terminal" in Spotlight or find it in /Applications/Utilities/).
-
Run the following commands to check the installed versions:
node -v
Expected Output: A version number (e.g.,
v18.16.0
)npm -v
Expected Output: A version number (e.g.,
9.5.1
)
-
Method 2: Using Homebrew (Recommended)
-
Install Homebrew (if you don't have it):
- Open Terminal and run:
Follow the prompts to install Homebrew.
/bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh](https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh))"
- Open Terminal and run:
-
Install Node.js:
- In Terminal, run:
brew update brew install node
- In Terminal, run:
-
Verify Node.js and npm Installation:
-
In Terminal, run:
node -v
Expected Output: A version number (e.g.,
v18.16.0
)npm -v
Expected Output: A version number (e.g.,
9.5.1
)
-
Install TypeScript Compiler (for both methods):
-
Open Terminal and run the following command to install TypeScript globally:
npm install -g typescript
-
Verify TypeScript Installation:
- Run the following command to check the installed version of the TypeScript compiler:
Expected Output: A version number (e.g.,
tsc -v
Version 5.0.4
)
- Run the following command to check the installed version of the TypeScript compiler:
Now you have npm and the TypeScript compiler installed on your macOS system.