I have tested this sequence several times on Debian Stretch 9.4 & 9.5 (and recently 9.8) – it works consistently. It is based on various documents which are available on the ERPNext forums. I have left my little scraps of notes in comment lines. The syntax is ZSH/BASH compliant if you want to copy/paste it.
I run it line by line instead of as a script so that I get properly warned if anything is wrong along the way.
The base install (v9.x) is the same as here. The IP address of this machine is 192.168.1.238, and I like to match the port to the IP, so in the end it will be running on http://192.168.1.238:8238 – but that’s just personal preference, and is not essential.
At the end of it, you’ll get the latest production version of ERPNext (v11 stable at the time of this update).