nodejs安裝和更新


之前安裝過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  - / usr / local /
cd  / usr / local /
mv node - v5. 10.1 - linux - x64 /  nodejs
ln  - / usr / local / nodejs / bin / node  / usr / local / bin
ln  - / 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 ```
鏈接:https://www.jianshu.com/p/e5868d6d4171


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM