Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can the terminal in Jupyter automatically run bash instead of sh

Tags:

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?

like image 208
Steven Lowenthal Avatar asked Nov 01 '15 20:11

Steven Lowenthal


People also ask

How do I change the terminal in Jupyter Notebook?

Windows Search (with admin rights) > "Edit the System Environment Variables" > Environment Variables > Highlight "path" > Edit > Add a new line with C:\Program Files\Git\bin > OK out of all windows.

Does Jupyter support bash?

JupyterLab terminals provide full support for system shells (bash, tsch, etc.) on Mac/Linux and PowerShell on Windows. You can run anything in your system shell with a terminal, including programs such as vim or emacs.

What Shell does Jupyter use?

Jupyter notebooks take the IPython shell to the next level. First of all, they're browser-based, not terminal-based. To get started, install jupyter .


2 Answers

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.

like image 167
Peter Ogden Avatar answered Oct 06 '22 06:10

Peter Ogden


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.

like image 20
Ken Pega Avatar answered Oct 06 '22 08:10

Ken Pega