繁体   English   中英

如何使用 Fish 管理我的节点版本 Shell

[英]How to manage my node version using Fish Shell

我昨天开始使用 fish 作为我的 shell,今天我尝试使用 yarn 在终端中运行我的 NextJs 应用程序,tailwind 给了我一个关于节点版本的错误。 我检查了一下,然后我注意到当前版本是 10.19.0。

在我的 zsh shell 中,我安装了节点、npm 和 nvm,我可以毫无错误地使用它们,但是在我的鱼 shell 中,只有节点存在。 我尝试使用以下命令在终端中安装 nvm:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash 

以下 output 是:

=> nvm is already installed in /home/gabriel/.nvm, trying to update using git
=> error: pathspec 'v0.31.4' did not match any file(s) known to git

=> Source string already in /home/gabriel/.profile
main: linha 293: /nvm.sh: Arquivo ou diretório não encontrado
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/home/gabriel/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm⏎ 

最后一条指令为我提供了可用于运行 nvm 的命令,但是当我运行它们时,出现错误

给出的命令

export NVM_DIR="/home/gabriel/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Output

~/.nvm/nvm.sh (line 942): Unexpected ')' found, expecting '}'
      "${NVM_NODE_PREFIX}")
                          ^
from sourcing file ~/.nvm/nvm.sh
        called on line 185 of file /usr/share/fish/config.fish
in function '.' with arguments '/home/gabriel/.nvm/nvm.sh'
source: Error while reading file “/home/gabriel/.nvm/nvm.sh”

所以,我找到了两种方法,

一种是仅将nvm与 bash 一起使用。每当您需要使用nvm命令时,请使用bash 然后 go 回到fish并做所有与节点相关的事情,在 bash 中更改nvm use [version] 。然后在 fish 中工作,它仍然会使用 NVM 集的版本。

另一种是,在fish中安装curl,安装fisher,安装bass插件支持bash风格,

sudo apt install curl

curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher

fisher install edc/bass

创建nvm.fish sudo nano ~/.config/fish/functions/nvm.fish

将此代码添加到文件 nvm.fish

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

现在,您可以在 Fish 中使用nvm命令

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM