How to Launch Jupyter Notebook Quickly (Mac)
The Problem
You are tired of typing jupyter notebook
into your Terminal each time you want to launch a Jupyter Notebook on your Mac.
NOTE: This post was inspired by a similar tutorial by Benjamin Dornel. His tutorial has details on how to create aliases on a Windows machine.
A Solution
You can create a zsh alias shortcut so that every time you type jn
, your computer recognizes it as jupyter notebook
.
This is a one-time fix that should take just a few minutes to set up by going through the following steps:
- Access the .zshrc file
- Add the line
alias jn="jupyter notebook"
- Save your changes
1. Access the .zshrc file
In your Terminal, type:
vim ~/.zshrc
This will open up a hidden file called .zshrc. The file might either be empty or have some existing content in it, which you can ignore. Here’s what mine looks like:
NOTE: You may see some tutorials talk about editing .bash_profile instead of .zshrc. The newer MacBooks now use zsh instead of bash, so I recommend editing the .zshrc file.
2. Add a line of code
To edit the .zshrc file in vim:
- Type
i
Once you do this, you should see — INSERT — appear at the bottom of the screen. You are now in edit mode in the vim text editor.
2. Add the line alias jn="jupyter notebook"
to the top of the file
You can use the up / down / left / right arrows on your keyboard to navigate around the file.
NOTE: Make sure to type the line exactly how you see it above. Notice the lack of spaces around the equal sign and the double quotes.
3. Save your changes
To save the vim file:
- Press
Esc
on your keyboard. This will switch you from edit mode to normal mode. - Next, type
:wq
to save your changes and quit vim.
Once you are out of vim, the final step is to reload the .zshrc file so that typing jn
will actually work.
source ~/.zshrc
Problem Solved!
You can now launch a Jupyter Notebook using the shortcut jn
. Give it a try!
To launch Jupyter Notebook:
(base) alice@Alices-MacBook-Pro ~ % jn
To open a particular notebook:
(base) alice@Alices-MacBook-Pro ~ % jn my_python_code.ipynb
There are other ways to quickly launch a Jupyter Notebook, but this is the one that I like the most and use daily when I do data analysis. 👩🏻💻