nvm 可以在 bash shell 中工作,但不能在 sh shell 中工作

问题描述 投票:0回答:2
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.1/install.sh |          bash - && \ 
    . $HOME/.nvm/nvm.sh && \
    nvm ls && \
    chmod -R 777 /bin/ && \ 
    nvm install 18 && \
    nvm install 16 && \
    nvm install 14 && \
    nvm alias default 14 && \
    nvm use default && \
    nvm ls && \
    node -v

我需要 nvm 来构建多个节点版本。我在我的 Jenkins docker 代理上使用它。但在 Jenkins 中,我找不到 nvm。

node.js docker jenkins nvm
2个回答
0
投票

我在谷歌上搜索这是否是一个已知问题,因为我只是偶然发现了同样的问题,即使不是非常相似的问题。由于某种原因,nvm 期望有一个交互式 bash shell,并且一旦“.”它们的东西就可以工作。命令位于 bashrc 中。

NVM 的编写假设您将在交互式 bash shell 中运行它。例如,请参阅 nvm.sh 末尾的这段代码:

nvm_process_parameters() {
  local NVM_AUTO_MODE
  NVM_AUTO_MODE='use'
  while [ $# -ne 0 ]; do
    case "$1" in
      --install) NVM_AUTO_MODE='install' ;;
      --no-use) NVM_AUTO_MODE='none' ;;
    esac 
    shift
  done 
  nvm_auto "${NVM_AUTO_MODE}"
}

$#
根本无法在 bourne shell 中工作,因此脚本始终将“use”设置为 NVM_AUTO_MODE。

您的问题可能有所不同。但底线是:在容器中安装 bash,并在 bash 下运行它。

bash -c " . $HOME/.nvm/nvm.sh ; nvm ls ; "

此外,我还会进行更多检查和步骤,以将您直接通过 wget 管道传输到 shell 中的文件添加到其中,并使其成为 COPY 步骤或其他步骤。


0
投票

运行curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash - && \ bash -l -c ". $HOME/.nvm/nvm.sh ; nvm install 18; nvm install 16; nvm install 14; nvm ls; nvm 别名默认 14; nvm 使用默认值; node -v"

RUN echo "export NVM_DIR=$HOME/.nvm" >> ~/.profile
&& echo ".$HOME/.nvm/nvm.sh" >> ~/.profile

© www.soinside.com 2019 - 2024. All rights reserved.