본문 바로가기

Ubuntu

우분투에서 컴파일러, 실행파일 등의 여러 버전관리 방법

When you have multiple MPI implementations installed on the same machine (or multiple versions of the same MPI, e.g. a system-installed Open MPI vs. your own self-compiled Open MPI), you can control which one is used by your shell or your build scripts in several ways. Below are the key approaches:

1. Use full paths to “mpirun” (or “mpicc”, etc.)

 

If you install your new Open MPI in a custom prefix (e.g. /opt/openmpi-4.1.6/ or ~/software/openmpi-4.1.6/), you’ll usually have something like:

/opt/openmpi-4.1.6/bin/mpirun
/opt/openmpi-4.1.6/bin/mpicc
...

If you want to be absolutely certain you are using that MPI, call its binaries by their full path:

/opt/openmpi-4.1.6/bin/mpirun -np 4 ./my_executable

This is the simplest, most explicit way to ensure you’re using the custom version.

2. Adjust PATH and LD_LIBRARY_PATH

 

You can prepend the path to your new MPI to the front of your $PATH (so that shell finds it first before the system default). For example, if you added this line to your ~/.bashrc or ~/.zshrc:

export PATH=/opt/openmpi-4.1.6/bin:$PATH
export LD_LIBRARY_PATH=/opt/openmpi-4.1.6/lib:$LD_LIBRARY_PATH

Then, after reloading your shell (source ~/.bashrc), typing mpirun or mpicc will pick the new version. If you later want to revert to the system version, you can either remove or comment out these lines or open a shell without them.

3. Use the Debian/Ubuntu “update-alternatives” system

 

Ubuntu provides a mechanism to manage multiple versions of the same program, known as update-alternatives. You can register both “mpirun” binaries as alternatives and then choose which one is the system default.

 

Example steps

1. Register your new MPI as an alternative (assuming you installed in /opt/openmpi-4.1.6):

sudo update-alternatives --install /usr/bin/mpirun mpirun /opt/openmpi-4.1.6/bin/mpirun 50
sudo update-alternatives --install /usr/bin/mpirun mpirun /usr/bin/mpirun 10

 The “50” and “10” are priorities—the higher one is preferred by default.

 

2. Select which version you want:

sudo update-alternatives --config mpirun

You’ll see a menu listing the possible choices (the system Open MPI vs. the new one).

 

3. Check which mpirun is active:

which mpirun
mpirun --version

 

 

If you also want multiple mpiccs or mpicxx, you would need to register them in a similar way. Some people prefer to manage an entire set of MPI executables via alternatives, while others just rely on PATH or use full paths.

4. Use environment modules

 

Another approach is to install and manage MPI versions through “environment modules” (e.g., the module command). Then you can do:

module load openmpi/4.1.6
# or
module unload openmpi/4.1.6
module load openmpi/4.0.5

This approach keeps your environment clean and makes switching versions straightforward. However, it requires setting up modules or using something like Lmod.

Summary

 Full path approach (quick, direct).

 Prepend custom location to $PATH (simple, but you need to watch out for conflicts).

 update-alternatives (Debian/Ubuntu’s official way to manage multiple versions).

 Environment modules (flexible if you frequently switch between versions).

 

Either way, you can install your custom-built Open MPI in a separate directory and pick which one to use at runtime or build time by controlling your $PATH or by calling the desired mpirun/mpicc explicitly.

'Ubuntu' 카테고리의 다른 글

Midnight Commander - Local Machine  (0) 2025.05.01
로그파일 검색 방법  (0) 2025.04.14
클립보드 복사용 VIM  (0) 2025.02.05
Glances  (1) 2025.01.25
Directories - 1  (1) 2025.01.16