Jupyter Notebook will not start: permission denied
Permission deniedShort answer
Jupyter writes connection files and settings into your user folders every time it starts. It fails with permission denied when those folders belong to root, usually after an earlier sudo run, or when the runtime location is not writable for your account. Give the folders back to your user, or point Jupyter at a directory you own.
Fix it fast
1Find out which cause you have
List who owns the Jupyter folders. Anything owned by root is the problem.
ls -ld ~/.jupyter ~/.local/share/jupyter ~/.local/share/jupyter/runtime echo "$JUPYTER_RUNTIME_DIR"2Match what you see, then jump to its fix
What does the error look like?
Permission denied
Cause 1 of 2
The Jupyter folders are owned by root
1Check
Jupyter keeps config in ~/.jupyter and data, with a runtime subfolder, in ~/.local/share/jupyter on Linux. If you ever ran jupyter with sudo, root created files there that your normal user cannot change.
find ~/.jupyter ~/.local/share/jupyter ! -user "$USER" 2>/dev/null | head2Fix
Give the folders back to your user, recursively, then start Jupyter without sudo.
sudo chown -R "$USER":"$(id -gn)" ~/.jupyter ~/.local/share/jupyter3Verify
The first command lists nothing, and Jupyter starts.
find ~/.jupyter ~/.local/share/jupyter ! -user "$USER" 2>/dev/null | head
jupyter notebook --no-browserConfirmed by docs.jupyter.org
Cause 2 of 2
The runtime directory cannot be written by your account
1Check
Runtime files live in the runtime subfolder of the data directory unless JUPYTER_RUNTIME_DIR says otherwise.
echo "$JUPYTER_RUNTIME_DIR"; ls -ld ~/.local/share/jupyter/runtime2Fix
Point JUPYTER_RUNTIME_DIR at a folder you own, for this shell or in your profile.
mkdir -p "$HOME/jupyter-runtime"
export JUPYTER_RUNTIME_DIR="$HOME/jupyter-runtime"3Verify
The variable shows your folder, and the server starts.
echo "$JUPYTER_RUNTIME_DIR"
jupyter notebook --no-browserConfirmed by docs.jupyter.org
How do I stop it coming back?
- Never start Jupyter with sudo; install packages in a virtual environment you own.
- In Docker, run the notebook as a normal user and mount the data directory with that user's ownership.
- Keep the Jupyter folders out of shared or read-only locations, or move them with JUPYTER_DATA_DIR.
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?
Related fixes
Servers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
Ansible hangs, then times out waiting for the sudo prompt
a playbook using become seems to hang
Ansible ran sudo on the target and never saw the answer it expected.
3 causes, each with a fixServers
Apache on Ubuntu returns 404 Not Found for my site
The requested URL was not found on this server.
On Ubuntu a 404 from Apache usually means the request maps to a path that has no file.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
Apache warns that a ${VAR} config variable is not defined
${VAR} left unchanged in the configuration, with a warning in the error log
Apache expands ${VAR} from Define or from the shell environment that exists when the server starts.
3 causes, each with a fix