Linux环境下Node.js的安装配置
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
- {
- "name" : "TestNodejs",
- "version" : "0.1.0",
- "main" : "main.js"
- }
vi main.js
- const electron = require('electron');
- const app = electron.app; // Module to control application life.
- const BrowserWindow =electron.BrowserWindow; // Module tocreate native browser window.
- // Report crashes to our server.
- electron.crashReporter.start();
- // Keep a global reference of the windowobject, if you don't, the window will
- // be closed automatically when theJavaScript object is garbage collected.
- var mainWindow = null;
- // Quit when all windows are closed.
- app.on('window-all-closed', function() {
- //On OS X it is common for applications and their menu bar
- //to stay active until the user quits explicitly with Cmd + Q
- if(process.platform != 'darwin') {
- app.quit();
- }
- });
- // This method will be called when Electronhas finished
- // initialization and is ready to createbrowser windows.
- app.on('ready', function() {
- //Create the browser window.
- mainWindow = new BrowserWindow({width: 800, height: 600});
- //and load the index.html of the app.
- mainWindow.loadURL('file://' + __dirname + '/index.html');
- //Open the DevTools.
- mainWindow.webContents.openDevTools();
- //Emitted when the window is closed.
- mainWindow.on('closed', function() {
- // Dereference the window object, usually you would store windows
- // in an array if your app supports multi windows, this is the time
- // when you should delete the corresponding element.
- mainWindow = null;
- });
- });
vi index.html
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Hello World!</title>
- </head>
- <body>
- <h1>Hello World!</h1>
- We are using node<script>document.write(process.versions.node)</script>,
- Chrome<script>document.write(process.versions.chrome)</script>,
- and Electron<script>document.write(process.versions.electron)</script>.
- </body>
- </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的安装配置的更多相关文章
- linux环境下redis数据库的安装|配置|启动
安装 下载:打开redis官方网站,推荐下载稳定版本(stable) 解压 tar zxvf redis-3.2.5.tar.gz 复制:推荐放到usr/local目录下 sudo mv -r red ...
- win 环境下 node.js环境变量
在win 环境下 node.js环境变量有两种情况: (1)开发环境(development):开发环境是程序猿们专门用于开发的服务器,配置可以比较随意, 为了开发调试方便,一般打开全部错误报告. ...
- Node.js入门教程:Node.js如何安装配置并部署第一个网站
前言:作为一个资深的前端开发人员,不懂的Node.js 那你绝对是不能跟别人说你是资深的前端程序猿滴! 今天洋哥就来和大家一起学习被大牛称之为前端必学的技能之一Node! 那么Node到底是什么呢? ...
- Node.js:安装配置
ylbtech-Node.js:安装配置 1.返回顶部 1. ode.js 安装配置 本章节我们将向大家介绍在window和Linux上安装Node.js的方法. 本安装教程以Node.js v4.4 ...
- node.js的安装配置——前端的配置
最近琢磨了以下node.js的安装,npm的配置,使用gulp watch监听index.html文件的修改,利用服务器打开网页. 打开自己写的网页不要本地双击打开,这样打开的网址是file:///E ...
- window下 node.js 的安装
下载安装文件 Node.js安装包及源码下载地址为:https://nodejs.org/en/download/. 32 位安装包下载地址 : https://nodejs.org/dist/v4. ...
- Linux环境下JDK/Eclipse一键安装脚本
-------------------------------------------------------------------- author:jiangxin Email:jiangxinn ...
- Centos6.8 下 Node.js 的安装
思路:采用编译好的文件进行安装 一 使用 wget 下载 到 Node.js 官网(https://nodejs.org/en/download/) 选择要下载的编译版本(Source Code) / ...
- 在Linux环境下采用压缩包方式安装JDK 13
本文地址:https://www.cnblogs.com/oberon-zjt0806/p/11663731.html 可以,转载,出处,格式,懂?? 什么是JDK?? 好吧如果你不知道这个问题的话我 ...
随机推荐
- Python基础(协程函数、内置函数、递归、模块和包)-day05
写在前面 上课第五天,打卡: 凭着爱,再回首: 一.协程函数(生成器:yield的表达式形式) 1.yield 的语句形式: yield 1 - 这种方式在 Python基础(函数部分)-day04 ...
- u-boot移植(十三)---代码修改---裁剪及环境变量 二
一.错误处理 上一节遇到一个错误: print一下: 发现我们在jz2440.h中静态写的网络参数都没有写进去. dm9000 address not set. dm9000的地址未设置. 这里对应两 ...
- 第17月第7天 iOS 数组越界,防Crash处理
1. 上面方法已经可以避免crash,为了避免冗余的代码,写一个NSArray的分类,利用runtime替换NSArray的对象方法objectAtIndex:,在这里进行判断,捕获异常: #impo ...
- CF448C Painting Fence (贪心分治)
题面 \(solution:\) 一道蛮水的分治题,但思想很不错(虽然我还是非常天真的以为是积木大赛原题,并且居然还有30分) 看到这个题目,根据贪心的一贯风格,我们肯定能想到将整个栅栏的下面某部分直 ...
- D - Searching the String (AC自动机)
题目链接:https://cn.vjudge.net/contest/281961#problem/D 题目大意:给你一个模式串,然后给你多个匹配串,匹配串的类型是包括可以覆盖的以及不可覆盖的. 具体 ...
- django学习~第四篇
django表单 1 今天继续来学学django的表单 首先介绍下http的方法,这是最基本的 GET 方法 GET一般用于获取/查询 资源信息,以?分割URL和传输数据 ...
- Jquery对当前日期的操作(格式化当前日期)
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- FPN 学习笔记
通常,利用网络对物体进行检测时,浅层网络分辨率高,学到的是图片的细节特征,深层网络,分辨率低,学到的更多的是语义特征. 1).通常的CNN使用如下图中显示的网络,使用最后一层特征图进行预测 例如VGG ...
- sql 查询名字中有_的员工
select * from emp where ename like '%\_%' escape '\' ;\可以换作任意的字符 select * from emp where ename like ...
- python 历险记(四)— python 中常用的 json 操作
目录 引言 基础知识 什么是 JSON? JSON 的语法 JSON 对象有哪些特点? JSON 数组有哪些特点? 什么是编码和解码? 常用的 json 操作有哪些? json 操作需要什么库? 如何 ...