CentOS 7 install nodejs

How To Install Latest Nodejs and NPM on CentOS/RHEL 7/6/5

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Latest version node.js yum repository is maintaining by its official website. We can add this yum repository to our **CentOS/RHEL 7/6/5 **Systems and install node.js with few easy commands.

Step 1 – Add Node.js Yum Repository

First we will add node.js yum repository in our system provided by nodejs official website. You also need development tools to build native addons to be installed on your system.
# yum install -y gcc-c++ make
# curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -

Step 2 – Install Node.js and NPM

After adding yum repository in your system, lets install Nodejs package. NPM will also be installed with node.js. This command will also install many other dependent packages on your system.

# **yum install nodejs**

Step 3 – Check Node.js and NPM Version

After installing node.js verify and check the installed version. You can find more details about current version on node.js official website.
$node -v
v6.2.0
Also check the version of npm.
$npm -v
3.8.9

Step 4 – Create Demo Web Server (Optional)

This is an optional step. If you want to test your node.js install. Lets create a web server with “Welcome Node.js” text. Create a file demo_server.js
$ vim demo_server.js
and add following content
var http = require('http');http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Welcome Node.js');}).listen(3001, "127.0.0.1");console.log('Server running at http://127.0.0.1:3001/');
Now start the web server using below command.
$node --debug demo_server.js
debugger listening on port 5858Server running at http://127.0.0.1:3001/
Web server has been started on port 3001. Now access http://127.0.0.1:3001/ url in browser.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • npm install -g hexo-clisudo npm install -g hexo-clinode -...
    iOS的Developer阅读 14,775评论 2 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,695评论 19 139
  • 甘德礼,(SFBT治疗的基本原则与治疗理念)持续原创分享第15天 今天看到红皮书这一段,觉得很有意义,虽然刘老师已...
    华南帝虎阅读 433评论 0 2
  • 数组的unset函数测试: 结果是: 可见,key也消失了 对象的unset测试 属性也消失了
    Vos井宝阅读 539评论 0 0
  • 8月31日,星期四,晴 今天是暑假的最后一天,早上,我便对女儿说:“今天你在家睡个懒觉吧,暑假最后一天了,自己在家...
    月儿贝贝阅读 330评论 0 0

友情链接更多精彩内容