【Fis】mac/开发机安装nvm、node、fis、patchelf等

step1:安装nvm

先装nvm,这是node的一个管理器,官网说明:https://github.com/nvm-sh/nvm/blob/master/README.md#installing-and-updating

方法一:

直接用curl安装:curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh|bas

也可以使用wget安装:wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh|bash

执行完命令之后如下图所示:

exportNVM_DIR="$HOME/.nvm"[-s"$NVM_DIR/nvm.sh"]&&\."$NVM_DIR/nvm.sh"#This loads nvm 写入~/.bash_profile 或者 ~/.zshrc 或者 ~/.profile 或者 ~/.bashrc文件中。一般第一步之后,会自动写入其中一个文件,我的就是写入了~/.bash_profile这个文件

然后执行一下:source ~/.bash_profile

最后用 nvm --version 就可以查看已安装的nvm版本

方法二:

后来我把nvm卸了,想装一个最新的,但是用 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh|bash 这个命令,一直连不上

按往上说的『先确保https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh是否可以访问,如果不可访问,则需要配置hosts文件。通过https://www.ipaddress.com/查询IP,得到199.232.68.133

hosts文件增加  199.232.68.133 raw.githubusercontent.com』试了,也不行,于是就按官网说的方法手动安装:

1、cd ~,然后:git clone https://github.com/nvm-sh/nvm.git .nvm

2、cd ~/.nvm,然后:git checkout v0.35.3

3、然后在~/.bash_profile加上以下三句话

exportNVM_DIR="$HOME/.nvm"

[-s"$NVM_DIR/nvm.sh"]&&\."$NVM_DIR/nvm.sh"#This loads nvm

[-s"$NVM_DIR/bash_completion"]&&\."$NVM_DIR/bash_completion"#This loads nvm bash_completion

4、然后执行:source ~/.bash_profile

就装好了


卸载nvm也很简单:

1、先移出nvm相关目录

cd ~

rm -rf .nvm

2、然后移除掉~/.profile, ~/.bash_profile, ~/.zshrc, ~/.bashrc文件中关于nvm的配置(我直接删掉~/.bash_profile里的配置即可)

3、重新执行一下配置文件:source ~/.bash_profile


step2:安装node

使用命令:nvm install node 可以直接安装

当然也可以用命令:nvm ls-remote 查看远程node版本号,然后再用命令nvm install [node版本号] 安装指定的版本

node -v 可查询安装的版本

常用命令

nvm list 查看已经安装的版本

nvm list installed 查看已经安装的版本

nvm list available 查看网络可以安装的版本

nvm version 查看当前的版本

nvm install 安装最新版本

nvm install <version>:安装指定版本的node

nvm use <version> ## 切换使用指定的版本node

nvm ls 列出所有版本

nvm current显示当前版本

nvm alias <name> <version> ## 给不同的版本号添加别名

nvm unalias <name> ## 删除已定义的别名

nvm reinstall-packages <version> ## 在当前版本node环境下,重新全局安装指定版本号的npm包

nvm on 打开nodejs控制

nvm off 关闭nodejs控制

nvm proxy 查看设置与代理

nvm node_mirror [url] 设置或者查看setting.txt中的node_mirror,如果不设置的默认是 https://nodejs.org/dist/

nvm npm_mirror [url] 设置或者查看setting.txt中的npm_mirror,如果不设置的话默认的是: https://github.com/npm/npm/archive/.

nvm uninstall <version> 卸载制定的版本

nvm use [version] [arch] 切换制定的node版本和位数

nvm root [path] 设置和查看root路径


step3:安装fis

使用命令 npm install -g fis3 进行安装

fis3 -v 可查询安装的版本


step4:安装fis3-smarty插件

使用命令:npm install -g fis3-smarty 安装

遇到报错:rollbackFailedOptional: verb npm-session f1ba88ea03ea69c3

解决方案:更换淘宝镜像源即可:npm config set registry https://registry.npm.taobao.org

(恢复原有源:npm config set registry http://registry.npmjs.org )


常用命令

1、fis3 server open -->打开web server的根目录(www目录)

2、fis3 release   -->将构建结果发布到web server 的目录下面

3、fis3 release -d +路径  -->构建结果发布到指定的目录下面

4、fis3 server  start   -->启动本地web server(浏览器将会被打开)

5、fis3 release -w   -->启动文件监听功能

6、fis3 release -wl   -->浏览器自动刷新

7、fis3 server -h  -->获取更多参数

8、fis3 server clean  --> 清空web server下面的www目录

9、fis3 inspect 可以查看每个文件对应分配到的属性


后来在使用fis插件推代码的时候,遇到报错:TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer


过程中遇到的问题

1、安装nvm时,curl报错curl: (35) SSL connect error

解决方案:yum update -y nss curl libcurl —> ssl过期了,更新下

2、更新完成后,wget nvm包仍旧有警告

解决方案:curl时加上 -k 参数,不验证证书

3、用nvm ls-remote命令,只有iojs出来没有node或者出 N/A

解决方案:替换镜像源,http不好使就用https。以下二选一:

export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/dist 

export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist

记得source ~/.bashrc

4、【未解决】使用node报错,各种依赖库找不到 

centos系统默认的glibc版本较低,需改为/opt/compiler下的gcc版本进行动态库链接,例如 gcc12

首先,确认对应gcc下的glibc版本是否支持,例如:

strings /opt/compiler/gcc-12/lib64/libc.so.6 | grep ^GLIBC_

strings /opt/compiler/gcc-12/lib64/libstdc++.so.6 | grep ^GLIBCXX_

然后,安装patchelf工具:

去官网下载合适的包:https://github.com/NixOS/patchelf/releases

然后解压接口:tar -zxvf patchelf-0.18.0-x86_64.tar.gz

查看版本:$HOME/bin/patchelf --version

最后,这一步还是没搞得定

$HOME/bin/patchelf --set-interpreter /opt/compiler/gcc-12/lib64/ld-linux-x86-64.so.2 ~/.nvm/versions/node/v22.6.0/bin/node

$HOME/bin/patchelf --set-rpath '/opt/compiler/gcc-12/lib64:/usr/lib64' ~/.nvm/versions/node/v22.6.0/bin/node

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。