ubuntu对新手的友好性是毋庸置疑的。稳定性的话centos各有千秋吧。css
若是是本身本地VM上运行的话,经常使用的ubuntu14.04推荐下载。前不久买了阿里的云服务器,Ubuntu只支持16.04,今天就来从新配一下环境。node
首先链接到咱们的服务器,这里我用的finalShell终端链接,很方便,支持复制粘贴,可视化文件夹。git
看一下软件效果图:github
一、咱们先对工具包进行一次更新,防止后面的麻烦:ubuntu
sudo apt-get update
二、安装服务器维护平常依赖(考虑到后期使用git 因此这里安了git),执行命令vim
sudo apt-get install git vim openssl build-essential libssh-dev wget curl
到这里环境就整舒服了centos
一、执行如下代码安装nvm,安装命令能够在github上搜索nvm找到。bash
地址:https://github.com/nvm-sh/nvm服务器
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.33.2/install.sh | bash nvm ls
二、安装成功后咱们执行 nvm ls 查看nvm的安装状况,大体状况以下图:ssh

3.这里一般会提示 No Commond 错误不要怕,很正常,缺乏环境变量。咱们接下来进行配置:
cd ~/.nvm
touch .bash_profile
vim .bash_profile
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
source .bash_profile
这是由于尚未安装对应的nodejs
4.执行如下命令安装node.jsv8.1.2
nvm install v8.1.2
咱们进入node.js官网,这里说一下中文 版的没有测试这一块,英文版的地址:https://nodejs.org/en/about/
咱们在/目录下新建server.js.复制一下内容
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}/`); });
经过node server来运行代码,效果图以下:
到这里咱们的nodejs环境就安装完成了。