Change default working directory in JupyterLab on Linux

I’m new to JupyterLab. I want to change the default location notebooks are saved from ~/ (i.e. my home directory) to a mounted network location with the path /workspaces/Jupyter/ (or alternatively, another local directory I create outside of my home). I do not want all these .ipynb files cluttering up my home directory.

I looked at a number of answers, but as far as I can tell, none of them address my question because they are either specific to Windows or they focus on an older version of Jupyter. Also, because I am new to JupyterLab, I don’t want to screw things up by trying something that I’m not sure is correct. So I’m looking for the correct answer for changing the default working directory in JupyterLab on Linux.

These are the config files I currently have:

~/.jupyter/
β”œβ”€β”€ lab
β”‚   β”œβ”€β”€ user-settings
β”‚   β”‚   └── @jupyterlab
β”‚   β”‚       β”œβ”€β”€ console-extension
β”‚   β”‚       β”‚   └── tracker.jupyterlab-settings
β”‚   β”‚       β”œβ”€β”€ fileeditor-extension
β”‚   β”‚       β”‚   └── plugin.jupyterlab-settings
β”‚   β”‚       └── notebook-extension
β”‚   β”‚           └── tracker.jupyterlab-settings
β”‚   └── workspaces
β”‚       └── default-37a8.jupyterlab-workspace
β”œβ”€β”€ migrated
└── nbconfig
    └── notebook.json
8 directories, 6 files

None of them contain the config keys I saw mentioned in the reference pages I checked.

$ grep -irP '(root_dir|notebook_dir)' ~/.jupyter/
$ echo $?
1

References:
(EDIT: I am only allowed 2 links, but I checked many more)

1 Like

The question on SO that you linked has a β€œ2021 update” from me (path - How to change the Jupyter start-up folder - Stack Overflow), but I will quote it here for convenience:

For recent nbclassic and JupyterLab>=3 use c.ServerApp.root_dir instead of c.NotebookApp.notebook_dir.

For context see migration guide and this question on differences between server and notebook.

So you would run jupyter server --generate-config and should be able to grep-find root_dir (even better, I think it will tell you where the config got generated into).

2 Likes

Thank you for answering here. I appreciated your SO answer. However, the part missing from your SO answer (unless I overlooked it) is:

jupyter server --generate-config

That might be obvious to some people, but all I knew was that the command you list there:

jupyter notebook --generate-config

was not what I needed since I’m running JupyterLab. Without your answer here, I was not able to put together the solution.