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?? 好吧如果你不知道这个问题的话我 ...
随机推荐
- 解决iOS10下Meta设置user-scalable=no无效问题
苹果为了提高Safari中网站的辅助功能,屏蔽了Meta下的user-scalable=no功能 所以在iOS10下面,就算加上user-scalable=no,Safari浏览器也能支持手动缩放 解 ...
- 常用的Date对象和Math对象方法
Date对象方法: 当前用户本地时间 let time = new Date(); 获取整数年 console.log(time.getFullYear()); 获取当前月(月份要加1) consol ...
- 一个单js文件也可以运行vue
新建一个hello.html文件,输入以下内容: <html> <head> <title></title> <script src=" ...
- 02、@PropertySource指定配置文件的属性映射到JavaBean属性
零.@PropertySource 功能类似于 <context:property-placeholder location="classpath*:/config/load.prop ...
- UE4的AI学习(2)——官方案例实例分析
官方给出的AI实例是实现一个跟随着玩家跑的AI,当玩家没有在AI视野里时,它会继续跑到最后看到玩家的地点,等待几秒后如果仍然看不到玩家,则跑回初始地点.官方的案例已经讲得比较详细,对于一些具体的函数调 ...
- CentOS6.8安装配置sonarqube6.4
下载最新版本的sonar(现在改名叫sonarqube) https://www.sonarqube.org/downloads/ 我下载的版本是Sonarqube6.4 1 使用前需要 ...
- 【BUG】xml读取异常Invalid byte 1 of 1-byte UTF-8 sequence
来自http://blog.csdn.net/chenyanbo/article/details/6866941 xml读取异常Invalid byte 1 of 1-byte UTF-8 seque ...
- [转]gcc -ffunction-sections -fdata-sections -Wl,–gc-sections 参数详解
背景 有时我们的程序会定义一些暂时使用不上的功能和函数,虽然我们不使用这些功能和函数,但它们往往会浪费我们的ROM和RAM的空间.这在使用静态库时,体现的更为严重.有时,我们只使用了静态库仅有的几个功 ...
- 【docx4j】docx4j操作docx,实现替换内容、转换pdf、html等操作
主要是想要用此功插件操作docx,主要的操作就是操作段落等信息,另外,也想实现替换docx的内容,实现根据模板动态生成内容的效果,也想用此插件实现docx转换pdf. word的格式其实可以用xml来 ...
- UML和模式应用4:初始阶段(6)--迭代方法中如何使用用例
1.前言 用例是UP和其他众多迭代方法的核心.UP提倡用例驱动开发. 2. 迭代方法中如何使用用例 功能需求首先定义在用例中 用例是迭代计划的重要部分,迭代是通过选择一些用例场景或整个用例来定义的 用 ...