Mac fish终端无法正常安装运行nvm解决方案

mac终端使用fish后,在安装nvm时,出现了安装成功但是编辑配置后无法成功source配置文件。

会出现以下的错误:

➜  ~ source .zprofile
~/.nvm/nvm.sh (line 386): Unexpected ')' found, expecting '}'
    *[!/]*/)
           ^
from sourcing file ~/.nvm/nvm.sh
    called on line 7 of file .zprofile
from sourcing file .zprofile
.: Error while reading file '/Users/zhiyu/.nvm/nvm.sh'
~/.nvm/bash_completion (line 5): Missing end to balance this if statement
if ! command -v nvm &> /dev/null; then
^^
from sourcing file ~/.nvm/bash_completion
    called on line 8 of file .zprofile
from sourcing file .zprofile
.: Error while reading file '/Users/zhiyu/.nvm/bash_completion'

### 且nvm找不到该命令

无奈在网上搜索了很多次,但是只有官方的安装教程方法,也没得到相对应的解决,无论是从homebrew或者通过git进行安装都没办法正常的使用。

在nvm官方的仓库中找到了相对于的解决办法[传送门]:

# ~/.config/fish/functions/nvm.fish
function nvm
  bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

# ~/.config/fish/functions/nvm_find_nvmrc.fish
function nvm_find_nvmrc
  bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc
end

# ~/.config/fish/functions/load_nvm.fish
function load_nvm --on-variable="PWD"
  set -l default_node_version (nvm version default)
  set -l node_version (nvm version)
  set -l nvmrc_path (nvm_find_nvmrc)
  if test -n "$nvmrc_path"
    set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
    if test "$nvmrc_node_version" = "N/A"
      nvm install (cat $nvmrc_path)
    else if test "$nvmrc_node_version" != "$node_version"
      nvm use $nvmrc_node_version
    end
  else if test "$node_version" != "$default_node_version"
    echo "Reverting to default Node version"
    nvm use default
  end
end

# ~/.config/fish/config.fish
# You must call it on initialization or listening to directory switching won't work
load_nvm > /dev/stderr

按照上面代码进行相对位置的相对文件进行配置,一般是没有的,创建并把相对文件的代码丢进去就好了,此刻就可以正常的使用nvm的命令了

当然进行上面的那步之前,需要文档里面说的,先安装bass

### 先clone bass代码
git clone https://github.com/edc/bass.git
### 然后进入到bass文件夹
cd bass
### 进行安装
make install

最最最重要的还是看官方的文档,网上查询还是不是那么靠谱。。。

本博客所有文章如无特别注明均为原创。作者:止语复制或转载请以超链接形式注明转自 止语博客
原文地址《Mac fish终端无法正常安装运行nvm解决方案

相关推荐

发表评论

路人甲
看不清楚?点图切换

网友评论(0)