之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录。
首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码,一种是编译后的文件。我就是按照网上源码的安装方式去操作编译后的文件,结果坑了好久好久。
(一) 编译好的文件
像上图中红色框里面的就是已经编译好的文件,选择好对应的linux版本下载即可,简单说就是解压后,在bin文件夹中已经存在node以及npm,如果你进入到对应文件的中执行命令行一点问题都没有,不过不是全局的,所以通过建立软链接的方式将这个设置为全局就好了。
1
2
3
4
5
|
tar xf node
-
v5.
10.1
-
linux
-
x64.tar.gz
-
C
/
usr
/
local
/
cd
/
usr
/
local
/
mv node
-
v5.
10.1
-
linux
-
x64
/
nodejs
ln
-
s
/
usr
/
local
/
nodejs
/
bin
/
node
/
usr
/
local
/
bin
ln
-
s
/
usr
/
local
/
nodejs
/
bin
/
npm
/
usr
/
local
/
bin
|
(二)通过源码编译
这种方式你下载的文件是Source code,由于我的linux版本是6.x的,默认的gcc-c++为4.4.7 版本,而下过来之后源码编译要求gcc-c++版本最低为4.8,于是我就去升级GCC-C++版本,结果因为是源码编译升级GCC-C++,编译了一个多小时,都没有编译完成!果断被坑...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
root>
# ./configure
WARNING: C
+
+
compiler too old, need g
+
+
4.8
or
clang
+
+
3.4
(CXX
=
g
+
+
)
creating .
/
icu_config.gypi
{
'target_defaults'
: {
'cflags'
: [],
'default_configuration'
:
'Release'
,
'defines'
: [],
'include_dirs'
: [],
'libraries'
: []},
'variables'
: {
'asan'
:
0
,
'gas_version'
:
'2.20'
,
'host_arch'
:
'x64'
,
'icu_small'
:
'false'
,
'node_byteorder'
:
'little'
,
'node_install_npm'
:
'true'
,
'node_prefix'
:
'/usr/local'
,
'node_release_urlbase'
: '',
'node_shared_http_parser'
:
'false'
,
'node_shared_libuv'
:
'false'
,
'node_shared_openssl'
:
'false'
,
'node_shared_zlib'
:
'false'
,
'node_tag'
: '',
'node_use_dtrace'
:
'false'
,
'node_use_etw'
:
'false'
,
'node_use_lttng'
:
'false'
,
'node_use_openssl'
:
'true'
,
'node_use_perfctr'
:
'false'
,
'openssl_fips'
: '',
'openssl_no_asm'
:
0
,
'target_arch'
:
'x64'
,
'uv_parent_path'
:
'/deps/uv/'
,
'uv_use_dtrace'
:
'false'
,
'v8_enable_gdbjit'
:
0
,
'v8_enable_i18n_support'
:
0
,
'v8_no_strict_aliasing'
:
1
,
'v8_optimized_debug'
:
0
,
'v8_random_seed'
:
0
,
'v8_use_snapshot'
:
'true'
,
'want_separate_host_toolset'
:
0
}}
creating .
/
config.gypi
creating .
/
config.mk
WARNING: warnings were emitted
in
the configure phase
|
(三)apt-get
还有一种就是乌班图下的apt-get方式,我之前就被这种方式坑了
sudo apt-get install nodejs
sudo apt-get install npm
这么装完你会发现,node命令不好使,nodejs命令可以用...
原文链接:https://www.cnblogs.com/kevinchou/p/5405540.html
- 配置更新源
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
- 添加 nodejs 更新源
sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
- 更新系统,并安装编译包
sudo apt-get update -y && sudo apt-get upgrade -y sudo apt-get install -y build-essential
- 安装Node.js,同时会自动安装npm
$ sudo apt-get install -y nodejs
- 更新node/npm/npx
$ sudo npx dist-upgrade
- 如果发生错误 ``` sudo npm cache verify sudo npm cache clean --force ``` - 更换淘宝源码 ``` sudo npm --registry http://registry.npm.taobao.org/ i -g nrm nrm use taobao sudo npx dist-upgrade ```