YouTip LogoYouTip

Nodejs Install Setup

In this chapter, we will introduce how to install Node.js on Windows, Linux, and macOS. The download address for Node.js installation packages and source code is: [https://nodejs.org/en/download](https://nodejs.org/en/download). !(#) * **Package Manager**: * Install using the system's built-in package manager (such as `apt`, `yum`, `brew`). * Automatically manages dependencies and updates, suitable for command-line users. * **Prebuilt Installer**: * Official installer provided, suitable for Windows and macOS. * Graphical installation interface, includes Node.js and npm. * **Prebuilt Binaries**: * Pre-compiled binary files, can be used directly after download and extraction. * Suitable for users with a technical background who wish to customize the installation location. * **Source Code**: * Node.js source code, requires user compilation. * Provides maximum flexibility, suitable for advanced users and developers needing custom configurations. The official Node.js website provides very detailed installation commands for different systems. You can choose the Node.js installation command script you need based on your platform. **The official website offers two versions:** * **LTS (Long Term Support):** Long-term support version, recommended for production environments. * **Current:** The latest version, containing the newest features. It is recommended to choose the LTS version, as it is more stable and has long-term technical support. > Node.js historical versions download address: [https://nodejs.org/dist/](https://nodejs.org/dist/) * * * ## Installing Node.js on Windows You can use one of the following two methods to install. ### 1. Windows Installer (.msi) !(#) Installation Steps: 1. Double-click the downloaded installer package, as shown below: !(#) 2. Click the Next button above, and the following interface will appear: !(#) 3. Check the option to accept the agreement, then click the Next button: !(#) 4. The default installation directory for Node.js is "C:Program Filesnodejs". You can change the directory and click the Next button: !(#) 5. Click Install to start installing Node.js. You can also click Back to modify previous configurations: !(#) Installation Process: !(#) Click the Finish button to exit the installation wizard. !(#) After installation is complete, we can test by executing the following commands in the command line or Windows PowerShell: node -v npm -v !(#) ### 2. Windows Binary File (.exe) Installation Click the "Prebuilt Binaries" option to download the binary file: !(#) **Installation Steps** Step 1: Double-click the downloaded installer package Node.exe, and the following interface will appear: !(#) Clicking the Run button will open a command line window: After installation is complete, we can test by executing the following commands in the command line or Windows PowerShell: node -v npm -v !(#) If you get the above output, it means you have successfully installed Node.js. ### Using Command Line Installation We can also install by executing the following commands in PowerShell: # Install fnm (Fast Node Manager) winget install Schniz.fnm # Configure fnm environment to automatically use fnm on directory change fnm env --use-on-cd | Out-String | Invoke-Expression# Download and install Node.js version 22 fnm use --install-if-missing 22# Verify the Node.js version in the environment is correct, output should be `v22.11.0` node -v # Should output `v22.11.0`# Verify the npm version in the environment is correct, output should be `10.9.0` npm -v # Should output `10.9.0` * * * ## Installing Node.js on Linux ### 1. Using the Official Installation Script !(#) This example uses the fnm package manager for illustration (you can also use nvm, etc.), with the following commands: # Install fnm (Fast Node Manager) curl -fsSL https://fnm.vercel.app/install | bash# Activate fnm source ~/.bashrc # Download and install Node.js fnm use --install-if-missing 22# Verify the Node.js version in the environment is correct node -v # Should output `v22.11.0`# Verify the npm version in the environment is correct npm -v # Should output `10.9.0` ### 2. Directly Using Pre-compiled Packages Click the "Prebuilt Binaries" option to download the binary file: !(#) The official Node.js website has changed the Linux download version to a pre-compiled version. We can download it directly and use it after extraction: # wget https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-arm64.tar.xz // Download# tar xf node-v22.11.0-linux-arm64.tar.xz // Extract# cd node-v22.11.0-linux-arm64/ // Enter the extracted directory# ./bin/node -v // Execute node command to check version The bin directory under the extracted files contains commands like node and npm. We can use the ln command to set up symbolic links: ln -s /usr/software/nodejs/bin/npm /usr/local/bin/ ln -s /usr/software/nodejs/bin/node /usr/local/bin/ ### 3. Installing Node.js from Source Code The following section will introduce how to install Node.js from source code on Ubuntu Linux. Other Linux systems, such as CentOS, have similar installation steps. Obtain the Node.js source code from Github: $ sudo git clone https://github.com/nodejs/node.gitCloning into 'node'... Modify directory permissions: $ sudo chmod -R 755 node Use **./configure** to create compilation files and proceed with installation: $ cd node $ sudo ./configure $ sudo make $ sudo make install Check the node version: $ node --version v0.10.25 * * * ## Installing on Mac OS ### 1. Using the Official Installation Script !(#) This example uses the nvm package manager for illustration (you can also use fnm, etc.), with the following commands: # Install nvm (Node Version Manager) curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash# Download and install Node.js (you may need to restart the terminal) nvm install 22# Verify the Node.js version in the environment is correct node -v # Should output `v22.11.0`# Verify the npm version in the environment is correct npm -v # Should output `10.9.0` ### 2. Using Pre-compiled Installers !(#) Download the .pkg file, double-click the .pkg file to launch the installation wizard. ### 3. Directly Using Pre-compiled Packages !(#) After downloading, extract the package, enter the bin directory of the compressed file, and you will see the pre-compiled node and npm, which can be used directly from the command line.
← Nodejs Http ServerNodejs Tutorial β†’