无法从本地计算机在远程服务器上 运行 捆绑命令

Cannot run bundle command on remote server from local computer

我创建了一个脚本,可以将 tar 文件复制到远程服务器,然后做一些事情 运行s:

[..]

kill $(lsof -i :3000 -t)

# Bundle up
cd $DIR && \
  bundle install && \
  RAILS_ENV=production bundle exec rake assets:precompile && \
  rails s -e production -p 3000 -d

我应该运行直接在远程服务器上./my-script.sh param,一切都很好。当我从本地计算机调用此脚本时它不起作用。它抱怨

./my-script.sh: line 18: bundle: command not found

当我在远程服务器上 运行 which bundle 时,我回来了:

/usr/share/rvm/gems/ruby-3.0.0/bin/bundle

在我的脚本中使用上面的代码,我遇到了很多错误。从本地计算机调用脚本时如何传递该错误?

您应该设置所有 ruby 和捆绑器环境变量以使用 bundle exec

如果使用了 rvm,你应该加载它:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

尝试通过以下方式了解 ruby 用户下服务器上 rvm 的所有环境: rvm env

运行起来像ssh example.com < ./bundle.sh

#!/bin/bash +ex
# bundle.sh

export PATH="/home/user/.rvm/gems/ruby-2.6.4/bin:/home/user/.rvm/gems/ruby-2.6.4@global/bin:/home/user/.rvm/rubies/ruby-2.6.4/bin:$PATH"
export GEM_HOME='/home/user/.rvm/gems/ruby-2.6.4'
export GEM_PATH='/home/user/.rvm/gems/ruby-2.6.4:/home/user/.rvm/gems/ruby-2.6.4@global'
export MY_RUBY_HOME='/home/user/.rvm/rubies/ruby-2.6.4'
export IRBRC='/home/user/.rvm/rubies/ruby-2.6.4/.irbrc'
unset MAGLEV_HOME
unset RBXOPT
export RUBY_VERSION='ruby-2.6.4'
source "$HOME/.rvm/scripts/rvm"

export RAILS_ENV=production

cd /path/ && bundle exec rails db:migrate:status
cd $DIR && \
  bundle install && \
  bundle exec rake assets:precompile && \
  rails s -e production -p 3000 -d