pgAdmin 4 installed with pip exits before it opens on port 5050
Fix it fast
Most common cause, 1 of 2The server-mode folders were never created
Create both folders once with sudo and give them to your own user, then start pgAdmin from the venv without sudo.
sudo mkdir /var/lib/pgadmin
sudo mkdir /var/log/pgadmin
sudo chown $USER /var/lib/pgadmin
sudo chown $USER /var/log/pgadmin
source pgadmin4/bin/activate
pgadmin4Short answer
pgAdmin 4 installed with pip runs in server mode, with its data in /var/lib/pgadmin and its log in /var/log/pgadmin. pip never creates those folders and a normal user cannot, so pgadmin4 prints Failed to create the directory or Permission denied and quits. Create both with sudo, chown them to the user running pgadmin4, and retry. Applies to pgAdmin 4 9.x.
Which cause do you have?
List both server-mode folders with their owners. A missing folder points to the first cause; a folder owned by root or by another account points to the second.
ls -ld /var/lib/pgadmin /var/log/pgadminThen find the line you see in this list and open its fix:
What does the error look like?
Failed to create the directory /var/lib/pgadmin:[Errno 13] Permission denied: '/var/lib/pgadmin'Create the directory /var/lib/pgadmin, ensure it is writeable by[Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
Cause 1 of 2
The server-mode folders were never created
You seels: cannot access '/var/lib/pgadmin': No such file or directory
Check
Failed to create the directory /var/lib/pgadmin means the pip-installed pgadmin4 tried to make its own data folder and was refused. Run from a wheel, pgAdmin uses server mode and system-wide paths, and pgAdmin's install page says these may have to be created first; under /var/lib and /var/log only root can do that.
pip show pgadmin4 | grep -i '^version'
ls -ld /var/lib/pgadminFix
Create both folders once with sudo and give them to your own user, then start pgAdmin from the venv without sudo.
sudo mkdir /var/lib/pgadmin
sudo mkdir /var/log/pgadmin
sudo chown $USER /var/lib/pgadmin
sudo chown $USER /var/log/pgadmin
source pgadmin4/bin/activate
pgadmin4Verify
On first start pgadmin4 asks for the email address and password of the initial pgAdmin user, and then serves the UI on port 5050.
curl -sI http://127.0.0.1:5050 | head -n 1Confirmed by pgadmin.org
Cause 2 of 2
The folders exist but belong to root or another account
You seels -ld shows root (or a different user) as owner, and the error names a path inside the folder, such as '/var/lib/pgadmin/sessions'
Check
A Permission denied error under /var/lib/pgadmin while the folder itself exists means it was made with sudo mkdir and never handed over. pgAdmin only checks whether each path exists and skips the ones that do; it does not test write access, so the failure appears one level down, when it tries to create its sessions and storage sub-folders or its database file.
whoami
ls -ld /var/lib/pgadmin /var/log/pgadminFix
Give both folders, and anything already created inside them, to the account that runs pgadmin4. If a service account runs it, use that name instead of $USER.
sudo chown -R $USER /var/lib/pgadmin /var/log/pgadminVerify
Your user can now write in both folders, and pgadmin4 starts without a traceback.
touch /var/lib/pgadmin/.write-test && rm /var/lib/pgadmin/.write-test
touch /var/log/pgadmin/.write-test && rm /var/log/pgadmin/.write-testConfirmed by github.com
How do I stop it coming back?
- Keep the two mkdir and two chown lines in the same setup script that creates the venv and runs pip install pgadmin4, so a new machine never starts pgAdmin before the folders exist.
- Start pgadmin4 as the account that owns the folders, and never with sudo from inside the venv.
- Pin pgadmin4 in a requirements file for that venv and read the release notes before you raise the version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.