As a developer, Node.js is undoubtedly one of the technologies you need to master. It is a JavaScript-based runtime environment that allows you to run JavaScript code on the server side. As we all know, Node.js comes with a npm package management tool, but when you need to install a specific version of Node.js or customize the source code, manual compilation and installation become a necessary process. In this article, we will teach you how to install Node.js 8 version through source code and some common customized compilation operations.
1. Preparations before installation
Before installing Node.js, you need to install some dependent libraries to ensure that no errors will occur during the compilation and installation process:
sudo apt-get update sudo apt-get install python build-essential libssl-dev curl
Here we use the Ubuntu system as the demonstration platform. Different Linux distributions and operating systems may require slightly different dependency libraries to be installed.
2. Download the Node.js 8 version source code
Open the official website of Node.js and download the Node.js 8 version source code tar package from the Downloads page. You can also use the following command to download the tar package:
wget https://nodejs.org/dist/v8.17.0/node-v8.17.0.tar.gz
Extract the downloaded tar package to the /usr/local/src directory:
sudo mkdir -p /usr/local/src sudo tar -xvzf node-v8.17.0.tar.gz -C /usr/local/src/
3. Compile and install Node.js 8 version
Enter the decompressed directory:
cd /usr/local/src/node-v8.17.0/
Start compilation and installation:
sudo ./configure sudo make sudo make install
After completing the compilation and installation, you can use the following command to check whether Node.js has been installed successfully:
node -v
If the terminal outputs information similar to the following, it means that Node.js has been installed successfully:
v8.17.0
4. Common customized compilation operations
1. Specify the installation directory
By default, Node.js will be installed in the /usr/local/bin directory, but as more and more Node.js versions are installed, the common commands here will become more confusing. Specifying the installation directory of Node.js can help us better manage different versions of Node.js.
Before starting compilation, specify the installation directory through the following command:
./configure --prefix=/usr/local/nodejs
After completing the compilation and installation, you can use the following command to check whether the installation in the specified directory has been successful:
/usr/local/nodejs/bin/node -v
2. Specify the CPU architecture
On Linux, processors under the same architecture will have better compatibility with the system. By specifying the processor architecture, you can improve the performance of Node.js in a specific CPU running environment.
Before starting compilation, specify the CPU architecture through the following command:
export TARGET_ARCH=x64 # 64 位处理器 export TARGET_ARCH=arm # ARM 处理器 export TARGET_ARCH=ppc64le # Power 8 处理器 export TARGET_ARCH=s390x # IBM s390x 处理器
3. Enable GDB debugging
GDB is a useful debugging tool under Linux systems. When developing complex applications, enabling GDB debugging can help us quickly find bugs.
Before starting compilation, enable GDB debugging through the following command:
./configure --debug
After compilation and installation, you can run the program under GDB:
gdb node
Conclusion
In this article, we introduce in detail how to install Node.js 8 version through source code, as well as the customized compilation operation of Node.js. Whether in the development process or in the customized deployment process, these skills will play an important role in helping you work.
The above is the detailed content of Install nodejs8 from source code. For more information, please follow other related articles on the PHP Chinese website!