---
# System prepended metadata

title: How-To `jupyter lab` in the sigma2 machines

---

# How-To `jupyter lab` in the sigma2 machines 

First you have to make sure you are on the right `conda` environment. First I'll create a conda env with `jupyter lab` already installed, while on any of the sigma2 machines. I will be using `Fram`
```
[username@login-1.FRAM ~]$ conda create -n my_env jupyterlab
```
then go into the `conda` environment
```
[username@login-1.FRAM ~]$ conda activate my_env
```
now I will start a `jupyter lab` session.
```
[username@login-1.FRAM ~]$ jupyter lab --no-browser &
```
this will give us a set of links similar to these
```
    http://localhost:8888/lab?token=686f045802c2861f31deeb80dde00ad188165c09cb68f116
 or http://127.0.0.1:8888/lab?token=686f045802c2861f31deeb80dde00ad188165c09cb68f116
```
open any of these links in your browser (chrome seems to work, but im not sure about other browsers), but take note of the part at the start of the links: `localhost:8888`. This is the port that is being used for `jupyter lab`.

In you local terminal type 
```
ssh -N -f -L localhost:[port]:localhost:[port] username@login-x.fram.sigma2.no
```
replacing `[port]` with the number from the link you got from `jupyter lab`, `username` with your username and `x` with the login node you were assigned when you logged in. You can check which node you are on by looking at your terminal `username@login-x.fram.sigma2.no` where `x` is the login node.

If you refresh your browser now you should be in your `jupyter lab` session.

Things to note: 
- You can specify the port when starting the session by adding `--port=[port]` to the command, if you prefer another port, but HPC advice to let jupyter take care of the ports.
- You can also use a different port for your local machine, just change the leftmost port in the command in your local machine to your preferred port. remember though that the port in the link has to also be set to the same one used in your local machine.