There is no doubt that ubuntu is friendly to novices. In terms of stability, centos have their own advantages.
If you are running on your own local VM, the commonly used ubuntu14.04 is recommended to download. I bought Ali's [Cloud Server] (https://cloud.tencent.com/product/cvm?from=10680) not long ago. Ubuntu only supports 16.04. Today I will reconfigure the environment.
First connect to our server, here I use the finalShell terminal connection, it is very convenient, supports copy and paste, and visualize folders.
Look at the software renderings:
sudo apt-get update
sudo apt-get install git vim openssl build-essential libssh-dev wget curl
The environment is comfortable here
Address: https://github.com/nvm-sh/nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.33.2/install.sh | bash
nvm ls
There will usually be a No Commond error. Don't be afraid. It is normal and lacks environment variables. Let's configure it next:
Enter nvm installation to the file directory
cd ~/.nvm
View the list of files in the directory ls
If there is no .bash_profile file, create and edit the file:
touch .bash_profile
vim .bash_profile
Paste the edited content directly:
export NVM_DIR="$HOME/.nvm"[-s "$NVM_DIR/nvm.sh"]&& \."$NVM_DIR/nvm.sh" # This loads nvm
[- s "$NVM_DIR/bash_completion"]&& \."$NVM_DIR/bash_completion" # This loads nvm bash_completion
Save and close this file. Update the environment changes just configured
source .bash_profile
Enter the nvm ls command to verify whether it is successful, *At this time, enter nvm ls and it is empty, as shown below: *
touch .bash_profile
vim .bash_profile
This is because the corresponding nodejs has not been installed
nvm install v8.1.2
Let’s go to the official website of node.js, here to talk about the Chinese version that is not tested, the English version’s address: https://nodejs.org/en/about/
We create a new server.js under the / directory. Copy the content
const http =require('http');const hostname ='127.0.0.1';const port =3000;const server = http.createServer((req, res)=>{
res.statusCode =200;
res.setHeader('Content-Type','text/plain');
res.end('Hello World\n');});
server.listen(port, hostname,()=>{
console.log(`Server running at http://${hostname}:${port}/`);});
Run the code through the node server, the effect diagram is as follows:
At this point, our nodejs environment is installed.
Recommended Posts