首页 > 系统 > Linux > 正文

Linux下Nodejs安装步骤(完整详细)

2019-11-02 16:54:31
字体:
来源:转载
供稿:网友

之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录。

 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码,一种是编译后的文件。我就是按照网上源码的安装方式去操作编译后的文件,结果坑了好久好久。

 

(一) 编译好的文件

像上图中红色框里面的就是已经编译好的文件,选择好对应的linux版本下载即可,简单说就是解压后,在bin文件夹中已经存在node以及npm,如果你进入到对应文件的中执行命令行一点问题都没有,不过不是全局的,所以通过建立软链接的方式将这个设置为全局就好了。

tar xf node-v5.10.1-linux-x64.tar.gz -C /usr/local/cd /usr/local/mv node-v5.10.1-linux-x64/ nodejsln -s /usr/local/nodejs/bin/node /usr/local/binln -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++,编译了一个多小时,都没有编译完成!果断被坑...

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.gypicreating ./config.mkWARNING: warnings were emitted in the configure phase 

(三)apt-get

还有一种就是乌班图下的apt-get方式,我之前就被这种方式坑了

sudo apt-get install nodejssudo apt-get install npm

这么装完你会发现,node命令不好使,nodejs命令可以用...

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表