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.

1 Like

The answer by @krassowski does not work for me on Fedora. It has an effect when starting ‘jupyter notebook’ but not when starting ‘jlab’. Also, first navigating to the ‘desired default directory’ and start ‘jlab’ from there doesn’t work.
This looks to me like a bug.

Anyway, just before sending that I am unable to find a solution, I found the --working-dir flag/option. And fortunately, that solution works :slight_smile:

Also, first navigating to the ‘desired default directory’ and start ‘jlab’ from there doesn’t work.

Use jlab . - the dot is important it means “current directory”.

But yes, jlab has a different CLI now which includes --working-dir. In general one can use jlab --help.

1 Like