AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1126478
Accepted
port5432
port5432
Asked: 2023-03-18 05:28:45 +0800 CST2023-03-18 05:28:45 +0800 CST 2023-03-18 05:28:45 +0800 CST

为什么 ssh 不能在 shell 中运行 rbenv?

  • 772

我正在尝试在远程服务器上运行 bash 脚本以通过 rbenv 安装 ruby​​。

#!/bin/bash
# ssh [email protected] 'bash -s' < configure.sh

echo "ruby 3.2.1"
rbenv install 3.2.1 --verbose
rbenv global 3.2.1

在远程服务器上rbenv已经为用户安装了deploy。如果我登录到该服务器,它运行正常。

❯ ssh [email protected]
deploy@ubuntu-focal:~$ rbenv
rbenv 1.2.0-59-g0704e65
Usage: rbenv <command> [<args>...]

但是如果我们尝试通过 ssh 运行命令,它就找不到了。

❯ ssh [email protected] "rbenv"
bash: rbenv: command not found

脚本也有同样的问题。

❯ ssh [email protected] 'bash -s' < configure.sh
ruby 3.2.1
bash: line 5: rbenv: command not found
bash: line 6: rbenv: command not found
bash: line 7: ruby: command not found
bash: line 9: gem: command not found
bash: line 10: gem: command not found
ssh
  • 1 1 个回答
  • 25 Views

1 个回答

  • Voted
  1. Best Answer
    vidarlo
    2023-03-18T06:00:15+08:002023-03-18T06:00:15+08:00

    简而言之,$PATH就是没有设置。

    Bash,当以交互模式或登录 shell 启动时,会读取一些配置文件,例如.profile和.bashrc:

    --noprofile
      Do not read either the system-wide startup file /etc/profile  or
      any   of  the  personal  initialization  files  ~/.bash_profile,
      ~/.bash_login, or ~/.profile.   By  default,  bash  reads  these
      files  when  it  is invoked as a login shell (see INVOCATION be-
      low).
    
    --norc Do  not  read  and  execute  the  personal  initialization  file
           ~/.bashrc if the shell is interactive.  This option is on by de-
           fault if the shell is invoked as sh.
    

    从man bash. 您启动一个非登录、非交互式 shell。

    或者,您的脚本应该:

    1. source ~/.bashrc
    2. $PATH自己指定
    3. 使用绝对路径
    • 2

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve