1.   官网下载Node.js

2.   安装Node.js

根据下载内容的不同,提供三种安装方法,选择自己喜欢的方式

2.1.   绿色免安装版(Linux(.tar.gz))

  • 解压Node-XXX.tar.gz

tar zxvf Node-XXX.tar.gz

  • 进入Node-XXX/bin目录,可以看到node 和 npm都存在

cd Node-XXX/bin

  • 查看node版本,执行命令看到版本号就说明你下载的内容妥妥的了

./node –v

  • 将node命令修改为全局(相当于windows的设置Path环境变量)

ln -s /home/XXX/Node-XXX/bin/node /usr/local/bin/node

ln -s /home/XXX/Node-XXX/bin/npm /usr/local/bin/npm

至此到任意目录执行node –v都是可用的了,哦了~

2.2.   源代码

  • 解压Node-XXX.tar.gz

tar zxvf Node-XXX.tar.gz

  • 进入解压后的根目录 执行

./configure

make

make install

  • 查看node版本,执行命令看到版本号就说明你安装的内容妥妥的了

./node –v

2.3.   apt-get硬安装

  • 只需要两条命令

sudo apt-get install nodejs

sudo apt-get install npm

有些人不喜欢这个方式,觉得很慢,可以尝试设置下国内的软件源地址,还是很快滴~

3.   安装Electron

安装好Node.js后,最好安装Electron这种图形用户界面来辅助提高开发效率,使用如下命令:<一定要sudo不然会安装失败,--registry选项提供淘宝服务器下载地址,不然可能会下载缓慢甚至失败>

  • 安装

sudo npm install electron-prebuilt -g--registry=https://registry.npm.taobao.org

  • 测试,输入electron看到下面的图形界面表示安装成功

electron

4.   安装asar(打包工具)

从Electron的运行界面可以看出,我们可以直接把node.js项目拖到其中运行,这里就需要一个将Node.js项目打包的工具——asar

  • 安装

sudo npm install -g asar --registry=https://registry.npm.taobao.org

安装成功后会显示如下图内容

  • 测试 (注意这里是大写的V)

asar -V

5.   第一个Node.js程序

  • 创建一个项目目录,创建项目文件

mkdir testNodejs

cd testNodejs

  • 创建项目文件

vi package.json

  1. {
  2. "name" : "TestNodejs",
  3. "version" : "0.1.0",
  4. "main" : "main.js"
  5. }

vi main.js

  1. const electron = require('electron');
  2. const app = electron.app;  // Module to control application life.
  3. const BrowserWindow =electron.BrowserWindow;  // Module tocreate native browser window.
  4. // Report crashes to our server.
  5. electron.crashReporter.start();
  6. // Keep a global reference of the windowobject, if you don't, the window will
  7. // be closed automatically when theJavaScript object is garbage collected.
  8. var mainWindow = null;
  9. // Quit when all windows are closed.
  10. app.on('window-all-closed', function() {
  11. //On OS X it is common for applications and their menu bar
  12. //to stay active until the user quits explicitly with Cmd + Q
  13. if(process.platform != 'darwin') {
  14. app.quit();
  15. }
  16. });
  17. // This method will be called when Electronhas finished
  18. // initialization and is ready to createbrowser windows.
  19. app.on('ready', function() {
  20. //Create the browser window.
  21. mainWindow = new BrowserWindow({width: 800, height: 600});
  22. //and load the index.html of the app.
  23. mainWindow.loadURL('file://' + __dirname + '/index.html');
  24. //Open the DevTools.
  25. mainWindow.webContents.openDevTools();
  26. //Emitted when the window is closed.
  27. mainWindow.on('closed', function() {
  28. // Dereference the window object, usually you would store windows
  29. // in an array if your app supports multi windows, this is the time
  30. // when you should delete the corresponding element.
  31. mainWindow = null;
  32. });
  33. });

vi index.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Hello World!</title>
  6. </head>
  7. <body>
  8. <h1>Hello World!</h1>
  9. We are using node<script>document.write(process.versions.node)</script>,
  10. Chrome<script>document.write(process.versions.chrome)</script>,
  11. and Electron<script>document.write(process.versions.electron)</script>.
  12. </body>
  13. </html>
 
  • 测试运行(在testNodejs根目录下执行命令)

electron .

  • 打包项目

cd ..

asar pack testNodejs testNodejs.asar

  • 测试运行打包内容,在文件系统界面将testNodejs.asar拖到Electron界面的”Drag your app here to run it”来运行

ENJOY Node.js !!!

Linux环境下Node.js的安装配置的更多相关文章

  1. linux环境下redis数据库的安装|配置|启动

    安装 下载:打开redis官方网站,推荐下载稳定版本(stable) 解压 tar zxvf redis-3.2.5.tar.gz 复制:推荐放到usr/local目录下 sudo mv -r red ...

  2. win 环境下 node.js环境变量

     在win 环境下 node.js环境变量有两种情况:  (1)开发环境(development):开发环境是程序猿们专门用于开发的服务器,配置可以比较随意, 为了开发调试方便,一般打开全部错误报告. ...

  3. Node.js入门教程:Node.js如何安装配置并部署第一个网站

    前言:作为一个资深的前端开发人员,不懂的Node.js 那你绝对是不能跟别人说你是资深的前端程序猿滴! 今天洋哥就来和大家一起学习被大牛称之为前端必学的技能之一Node! 那么Node到底是什么呢? ...

  4. Node.js:安装配置

    ylbtech-Node.js:安装配置 1.返回顶部 1. ode.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. 本安装教程以Node.js v4.4 ...

  5. node.js的安装配置——前端的配置

    最近琢磨了以下node.js的安装,npm的配置,使用gulp watch监听index.html文件的修改,利用服务器打开网页. 打开自己写的网页不要本地双击打开,这样打开的网址是file:///E ...

  6. window下 node.js 的安装

    下载安装文件 Node.js安装包及源码下载地址为:https://nodejs.org/en/download/. 32 位安装包下载地址 : https://nodejs.org/dist/v4. ...

  7. Linux环境下JDK/Eclipse一键安装脚本

    -------------------------------------------------------------------- author:jiangxin Email:jiangxinn ...

  8. Centos6.8 下 Node.js 的安装

    思路:采用编译好的文件进行安装 一 使用 wget 下载 到 Node.js 官网(https://nodejs.org/en/download/) 选择要下载的编译版本(Source Code) / ...

  9. 在Linux环境下采用压缩包方式安装JDK 13

    本文地址:https://www.cnblogs.com/oberon-zjt0806/p/11663731.html 可以,转载,出处,格式,懂?? 什么是JDK?? 好吧如果你不知道这个问题的话我 ...

随机推荐

  1. mysql用户权限分配专栏

    00x1创建新用户 通过root用户登录之后创建 创建新用户,用户名为testuser,密码为123456 : 1 grant all privileges on *.* to testuser@lo ...

  2. Linux 创建 时间命名 文件

    创建以 时间 命名文件:: touch /logs/`date +%Y-%m-%d_%d_%H:%M`.log touch "$(date +%Y-%m-%d_%H:%M:%S.TXT)

  3. 【通信】JDK中的URLConnection参数详解

    JDK中的URLConnection参数详解 来自:http://www.blogjava.net/supercrsky/articles/247449.html 针对JDK中的URLConnecti ...

  4. 位运算&,逻辑与and

    在python中,0是否 >>> True and True True >>> True and True True >>> 2 and 4 4 ...

  5. mysql 案例~mysql元数据的sql统计

    一 简介:今天我们来收集下提取元数据的sql 二 前沿: information_schema  引擎 memory 元数据收集表 三 sql语句: 1#没有使用索引的表统计 SELECT t.TAB ...

  6. android 解决子线程进行UI操作

    Android确实不允许在子线程中进行UI操作的,但我们有时必须在子线程里去执行一些耗时的任务,然后根据任务的执行结果来更新相应的UI控件. Android提供了一套异步消息处理机制,可以解决子线程中 ...

  7. 【Python】批量查询-提取站长之家IP批量查询的结果v1.0

    0 前言 写报告的时候为了细致性,要把IP地址对应的地区给整理出来.500多条IP地址找出对应地区复制粘贴到报告里整了一个上午. 为了下次更好的完成这项重复性很高的工作,所以写了这个小的脚本. 1 使 ...

  8. GCC编译过程与动态链接库和静态链接库

    1. 库的介绍 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常. 本质上来说库是一种可执行代码的二进制形式,可 ...

  9. YOLO(v1)

    <You Only Look once:Unified,Real-Time Object Dectection> 以前的图像检测网络其实都是在分类网络的基础上进行修改,而YoLo是将检测问 ...

  10. caffe源码阅读(1)_整体框架和简介(摘录)

    原文链接:https://www.zhihu.com/question/27982282 1.Caffe代码层次.回答里面有人说熟悉Blob,Layer,Net,Solver这样的几大类,我比较赞同. ...