32

I love the terminal feature and works very well for our use case where I would like students to do some work directly from a terminal so they experience that environment. The shell that launches automatically is sh and does not pick up all of my bash defaults. I can type "bash" and everything works perfectly. How can I make "bash" the default?

Steven Lowenthal
  • 646
  • 1
  • 5
  • 12

5 Answers5

24

Jupyter uses the environment variable $SHELL to decide which shell to launch. If you are running jupyter using init then this will be set to dash on Ubuntu systems. My solution is to export SHELL=/bin/bash in the script that launches jupyter.

Peter Ogden
  • 710
  • 5
  • 10
7

You can add this to your jupyter_notebook_config.py

c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}
El Belga
  • 176
  • 1
  • 5
  • 1
    This didn't work for me for some reason, do you know of any ideas why? – OneTwo Feb 04 '20 at 16:19
  • You may need to use `c.ServerApp.terminado_settings` instead of `NotebookApp` in newer versions. – krassowski Aug 18 '22 at 18:29
  • With either `c.NotebookApp.terminado_settings` or `c.ServerApp.terminado_settings`, I'm getting the following error with Posit Workbench: `rstudio-server.service: Failed with result 'exit-code'` – sharchaea Jan 03 '23 at 17:55
6

I have tried the ultimate way of switching system-wide SHELL environment variable by adding the following line to the file /etc/environment:

    SHELL=/bin/bash

This works on Ubuntu environment. Every now and then, the SHELL variable always points to /bin/bash instead of /bin/sh in Terminal after a reboot.

Also, setting up CRON job to launch jupyter notebook at system startup triggered the same issue on jupyter notebook's Terminal.

It turns out that I need to include variable setting and sourcing statements for Bash init file like ~/.bashrc in CRON job statement as follows via the command $ crontab -e :

    @reboot source /home/USERNAME/.bashrc && \
            export SHELL=/bin/bash && \
            /SOMEWHERE/jupyter notebook --port=8888

In this way, I can log in the Ubuntu server via a remote web browser (http://server-ip-address:8888/) with opening jupyter notebook's Terminal default to Bash as same as local environment.

Ken Pega
  • 534
  • 6
  • 9
0

Since Jupyter server 2.0.0, --ServerApp.terminado_settings="shell_command=['/bin/bash']" should work.

For jupyterlab==3.6, I can confirm myself it works:

jupyter lab --ServerApp.terminado_settings="shell_command=['/bin/bash']"

See also Juptyer Server PR #949.

nichoio
  • 6,289
  • 4
  • 26
  • 33
-8

With Jupyter running on Ubuntu 15.10, the Jupyter shell will default into /bin/sh which is a symlink to /bin/dash.

rm /bin/sh
ln -s /bin/bash /bin/sh

That fix got Jupyter terminal booting into bash for me.