Gitlab failiung to start on Debian 9.6 due to ruby

I’m having a issue on Debian 9.6. When installing gitlab an error is returned:

Setting up gitlab (8.13.11+dfsg1-8+deb9u3) ...
Creating/updating gitlab user account...
Making gitlab owner of /var/lib/gitlab...
Could not find gem 'rails (~> 4.2, >= 4.2.7.1)' in any of the gem sources listed
in your Gemfile.
dpkg: error processing package gitlab (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 gitlab
E: Sub-process /usr/bin/dpkg returned an error code (1)

I have checked and I have installed both the ruby and the ruby-rails package on the server and are the correct versions: ruby-rails is already the newest version (2:4.2.7.1-1).

I have unpacked the deb file and traced down the issue to this part in the postintall script:

if ! runuser -u ${gitlab_user} -- sh -c 'bundle --local --quiet'; then
  if [ "$1" = "triggered" ]; then
    # probably triggered in the middle of an system upgrade; ignore failure
    # but abort here
    echo "#########################################################################"
    echo "# Failed to detect gitlab dependencies; if you are in the middle of an #"
    echo "# upgrade, this is probably fine, there will be another attempt later.  #"
    echo "#                                                                       #"
    echo "# If you are NOT in the middle of an upgrade, there is probably a real  #"
    echo "# issue. Please report a bug.                                           #"
    echo "#########################################################################"
    exit 0
  else
    # something is really broken
    exit 1
  fi  
fi

Basically the error mentioned in the question is thrown by the following command: runuser -u ${gitlab_user} -- sh -c 'bundle --local --quiet'

Any suggestion on what could cause this?

I can’t see anything obvious, but could it be that you have two versions of rails installed? E.g. one via Debian packages and one via gem packages.

Neither can I see any related bugs on the Debian Bug Tracker System, so you might need to report it as a bug there.

In any case, the GitLab version on Debian Stretch is fairly old (8.13) when compared to the latest GitLab upstream version (11.5).

Instead, I would suggest installing the GitLab Omnibus package instead of the one from the archive, which you’ll also be able to easily upgrade when new GitLab versions are released:

OK thanks! I will give it a go.