Linux下安装Nodejs (一)

一、先去官网下载nodejs安装包

这里写图片描述

nodejs官网下载
或者

wget https://nodejs.org/dist/v8.11.3/node-v8.11.3-linux-x64.tar.xz

二、下载后解压到你指定的软件安装目录进行安装

tar xf node-v8.11.3-linux-x64.tar.xz
##输入下面命令
ln -s /home/lst/Destop/node-v8.11.3-linux-x64/bin/node /usr/local/bin/node
ln -s /home/lst/Destop/node-v8.11.3-linux-x64/bin/npm /usr/local/bin/npm

测试

#node -v
v8.11.3

#npm -v
5.6.0

三、使用node

1、新建一个test.js文件

vim test.js

2、写入一下代码

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {
        "Content-Type" : "text/plain" //输出类型
    });
    response.write("Hello World");// 页面输出
    response.end();
}).listen(8080); // 监听端口号
console.log(" listen 8080");

3、运行test.js文件

node test.js

这里写图片描述

猜你喜欢

转载自blog.csdn.net/post_mans/article/details/80949934