Changing the default port for iPython notebook server / Jupyter

To change port temporarily, indicate a different port number when we start jupyter notebook server from a terminal by firing following command.

jupyter notebook --port 9999

Read more https://jupyter.readthedocs.io/en/latest/running.html


Something is already listening on 80, you cannot bind 2 servers to the same port. Use a proxy that listen to 80, and redirect to your other servers and IPython base on URL, or address. Also don't use 80, use 443, if you are running a public server it should be over TLS for security.

Note that for any low port number you might need to increase the process privileges to root, potentially using sudo.


In Jupyter we can start the notebook on different port by two ways.

  1. Temporary port - By mentioning the port in args like below command we can run Jupyter on that port. But we have to mention the port in the command argument whenever we need to run Jupyter in a different port.
jupyter notebook --port 9999
  1. Permanent port Configuration - By changing the configuration we can run Jupyter on different port on the machine permanently. Please follow the below steps for that.

    • Open the configuration file in nano

    nano ~/.jupyter/jupyter_notebook_config.py

    • Change the port by changing the value of the below configuration

    c.NotebookApp.port = 9999

    • start the notebook by

    jupyter notebook

Bingo!!!


jupyter notebook --ip=0.0.0.0 --port=80 or
ipython notebook --ip=0.0.0.0 --port=80

is what i did to run ipython in my vagrant box. (Opened up the ports on the vagrant box to access it on my host mac)

usage: ipython [-h] [--certfile NOTEBOOKAPP.CERTFILE] [--ip NOTEBOOKAPP.IP]
               [--pylab [NOTEBOOKAPP.PYLAB]]
               [--log-level NOTEBOOKAPP.LOG_LEVEL]
               [--port-retries NOTEBOOKAPP.PORT_RETRIES]
               [--notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR]
               [--config NOTEBOOKAPP.CONFIG_FILE]
               [--keyfile NOTEBOOKAPP.KEYFILE] [--port NOTEBOOKAPP.PORT]
               [--transport KERNELMANAGER.TRANSPORT]
               [--browser NOTEBOOKAPP.BROWSER] [--script] [-y] [--no-browser]
               [--debug] [--no-mathjax] [--no-script] [--generate-config]

Incase the port is already occupied, see what's blocking it - inmy case it was an old instance of ipython which had not been terminated properly. I kiiled them all with this command

ps auxww | grep 'ipython' | awk '{print $2}' | xargs sudo kill -9