Problem deploying with git post-receive hook (bad interpreter)

Hello,

I am new to Jekyll. I am following the example here to deploy a site using git post-receive hooks. Everything works well when I push to the git repo from the same computer where the repo lives. However, if I push from a remote computer I get the following error:

remote: hooks/post-receive: /nfs/ghome/live/rapela/gems/bin/bundle: /usr/bin/ruby3.0: bad interpreter: No such file or directory                                                                              

I suspect that the reason for this problem is that git cannot find /usr/bin/ruby3.0. I don’t understand why this happens, as /usr/bin is in the PATH variable when the hook is runned.

This is my post-receive hook:

`

#!/bin/bash

while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo “Master ref received. Deploying …”

Install Ruby Gems to ~/gems

export GEM_HOME=$HOME/gems
export PATH=$GEM_HOME/bin:$PATH

TMP_GIT_CLONE=$HOME/tmp/bonsaiMLwww
GEMFILE=$TMP_GIT_CLONE/Gemfile
PUBLIC_WWW=$HOME/public_html/bonsaiML
GIT_dir=$HOME/bare_repos/bonsaiMLwww

echo Installing bundler …
gem install bundler

git clone $GIT_DIR $TMP_GIT_CLONE
echo PATH=$PATH
echo ruby3.0=which ruby3.0
echo ruby=which ruby
echo ls=which ls
echo BUNDLE_GEMFILE=$GEMFILE bundle install
BUNDLE_GEMFILE=$GEMFILE bundle install
echo BUNDLE_GEMFILE=$GEMFILE bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
BUNDLE_GEMFILE=$GEMFILE bundle exec jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
else
echo “Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server.”
fi
done
exit

`
And this is the full output from running the previous code

remote: Master ref received.  Deploying ...                                                                                                                                                                   
remote: Installing bundler ...                                                                                                                                                                                
remote: hooks/post-receive: line 18: gem: command not found                                                                                                                                                   
remote: Cloning into '/nfs/ghome/live/rapela/tmp/bonsaiMLwww'...                                                                                                                                              
remote: done.                                                                                                                                                                                                 
remote: PATH=/nfs/ghome/live/rapela/gems/bin:/usr/lib/git-core:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin                                             
remote: ruby3.0=                                                                                                                                                                                              
remote: ruby=                                                                                                                                                                                                 
remote: ls=/usr/bin/ls                                                                                                                                                                                        
remote: BUNDLE_GEMFILE=/nfs/ghome/live/rapela/tmp/bonsaiMLwww/Gemfile bundle install                                                                                                                          
remote: hooks/post-receive: /nfs/ghome/live/rapela/gems/bin/bundle: /usr/bin/ruby3.0: bad interpreter: No such file or directory                                                                              
remote: BUNDLE_GEMFILE=/nfs/ghome/live/rapela/tmp/bonsaiMLwww/Gemfile bundle exec jekyll build -s /nfs/ghome/live/rapela/tmp/bonsaiMLwww -d /nfs/ghome/live/rapela/public_html/bonsaiML                       
remote: hooks/post-receive: /nfs/ghome/live/rapela/gems/bin/bundle: /usr/bin/ruby3.0: bad interpreter: No such file or directory                                                                              
To ssh.swc.ucl.ac.uk:bare_repos/bonsaiMLwww                                                                                                                                                                   
   9bae69e..7d305d1  master -> master 

The server is running jekyll 4.3.2, bundler version 2.4.13, gem version 3.3.5 ubuntu version 22.04.2 LTS

I would greatly appreciate any hint.

Joaquin