You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/software/uenv/index.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -601,3 +601,63 @@ uenv image find @'*'%gh200
601
601
602
602
!!! note
603
603
The wild card `*` used for "all systems" must always be escaped in single quotes: `@'*'`.
604
+
605
+
## Custom environments
606
+
607
+
It is common practice to add `module` commands to `~.bashrc`, for example
608
+
```bash title="~/.bashrc"
609
+
# make my custom modules available
610
+
module use $STORE/myenv/modules
611
+
# load the modules that I always want in the environment
612
+
module load ncview
613
+
```
614
+
615
+
This will make custom modules available, and load `ncview`, every time you log in.
616
+
It is not posible to do the equivalent with `uenv start`, for example:
617
+
```bash title="~/.bashrc"
618
+
# start the uenv that I always use
619
+
uenv start prgenv-gnu/24.11:v2 --view=default
620
+
# ERROR: the following lines will not be executed
621
+
module use $STORE/myenv/modules
622
+
module load ncview
623
+
```
624
+
625
+
!!! question "Why can't I use `uenv start` in `~/.bashrc`?"
626
+
The `module` command uses some "clever" tricks to modify the environment variables in your current shell.
627
+
For example, `module load ncview` will modify the value of environment variables like `PATH`, `LD_LIBRARY_PATH`, and `PKG_CONFIG_PATH`.
628
+
629
+
The `uenv start` command loads a uenv, and __starts a new shell__, ready for you to enter commands.
630
+
This means that lines in the `.bashrc` that follow the command are never executed.
631
+
632
+
Things are further complicated because if `uenv start` is executed inside `~/.bashrc`, the shell is not a tty shell.
633
+
634
+
It is possible to create a custom command that will start a new shell with a uenv loaded, with additional customisations to the environment (e.g. loading modules and setting environment variables).
635
+
636
+
The first step is to create a script that performs the the customisation steps to perform once the uenv has been loaded.
637
+
Here is an example for an environment called `myenv`:
638
+
639
+
```bash title="~/.myenvrc"
640
+
# always add this line
641
+
source~/.bashrc
642
+
643
+
# then add customisation commands here
644
+
module use $STORE/myenv/modules
645
+
module load ncview
646
+
export DATAPATH=$STORE/2025/data
647
+
```
648
+
649
+
Then create an alias in `~/.bashrc` for the `myenv` environment:
650
+
651
+
```bash title="~/.bashrc"
652
+
alias myenv='uenv run prgenv-gnu/24.11:v2 --view=default -- bash --rcfile ~/.myenvrc'
653
+
```
654
+
655
+
This alias uses `uenv run` to start a new bash shell that will apply the customisations in `~/.myenvrc` once the uenv has been loaded.
656
+
Then, the environment can be started with a single command once logged in.
657
+
658
+
```console
659
+
$ ssh eiger.cscs.ch
660
+
$ myenv
661
+
```
662
+
663
+
The benefit of this approach is that you can create multiple environments, whereas modifying `.bashrc` will lock you into using the same environment every time you log in.
0 commit comments