본문 바로가기

OpenFOAM

Update-alternatives (Ubuntu Package Version 관리, GCC)

현재 버전확인은

gcc --version

gcc (Ubuntu 12.2.0-3ubuntu1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

dpkg -l | grep gcc

ii  gcc                                        4:12.2.0-1ubuntu1                        amd64        GNU C compiler
ii  gcc-11-base:amd64                          11.3.0-6ubuntu1                          amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-12                                     12.2.0-3ubuntu1                          amd64        GNU C compiler
ii  gcc-12-base:amd64                          12.2.0-3ubuntu1                          amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-12-base:i386                           12.2.0-3ubuntu1                          i386         GCC, the GNU Compiler Collection (base package)
ii  gcc-7                                      7.5.0-6ubuntu2                           amd64        GNU C compiler
ii  gcc-7-base:amd64                           7.5.0-6ubuntu2                           amd64        GCC, the GNU Compiler Collection (base package)
ii  gcc-8-base:amd64                           8.4.0-3ubuntu2                           amd64        GCC, the GNU Compiler Collection (base package)
ii  libgcc-12-dev:amd64                        12.2.0-3ubuntu1                          amd64        GCC support library (development files)
ii  libgcc-7-dev:amd64                         7.5.0-6ubuntu2                           amd64        GCC support library (development files)
ii  libgcc-s1:amd64                            12.2.0-3ubuntu1                          amd64        GCC support library
ii  libgcc-s1:i386                             12.2.0-3ubuntu1                          i386         GCC support library

추가 버전 설치는 지난 포스팅을 참조

 

우선 update-alternatives 명령에 대해서 살펴보도록 하자.

update-alternatives --help


Usage: update-alternatives [<option> ...] <command>

Commands:
  --install <link> <name> <path> <priority>
    [--slave <link> <name> <path>] ...
                           add a group of alternatives to the system.
  --remove <name> <path>   remove <path> from the <name> group alternative.
  --remove-all <name>      remove <name> group from the alternatives system.
  --auto <name>            switch the master link <name> to automatic mode.
  --display <name>         display information about the <name> group.
  --query <name>           machine parseable version of --display <name>.
  --list <name>            display all targets of the <name> group.
  --get-selections         list master alternative names and their status.
  --set-selections         read alternative status from standard input.
  --config <name>          show alternatives for the <name> group and ask the
                           user to select which one to use.
  --set <name> <path>      set <path> as alternative for <name>.
  --all                    call --config on all alternatives.

<link> is the symlink pointing to /etc/alternatives/<name>.
  (e.g. /usr/bin/pager)
<name> is the master name for this link group.
  (e.g. pager)
<path> is the location of one of the alternative target files.
  (e.g. /usr/bin/less)
<priority> is an integer; options with higher numbers have higher priority in
  automatic mode.

Options:
  --altdir <directory>     change the alternatives directory
                             (default is /etc/alternatives).
  --admindir <directory>   change the administrative directory
                             (default is /var/lib/dpkg/alternatives).
  --instdir <directory>    change the installation directory.
  --root <directory>       change the filesystem root directory.
  --log <file>             change the log file.
  --force                  allow replacing files with alternative links.
  --skip-auto              skip prompt for alternatives correctly configured
                           in automatic mode (relevant for --config only)
  --quiet                  quiet operation, minimal output.
  --verbose                verbose operation, more output.
  --debug                  debug output, way more output.
  --help                   show this help message.
  --version                show the version.

우선, gcc는 어떻게 버전 관리가 되고 있는지 확인해 보도록 하자. 위의 명령어에서 command --display를 써 보면

Usage: update-alternatives [<option> ...] <command>

Commands:
  --display <name>         display information about the <name> group.


update-alternatives --display gcc
update-alternatives: error: no alternatives for gcc

update-alternatives --display g++
update-alternatives: error: no alternatives for g++

아직 관리가 되고 있지 않은 것으로 확인 됨

등록은 --install로 하면 됨

Usage: update-alternatives [<option> ...] <command>

Commands:
  --install <link> <name> <path> <priority>
    [--slave <link> <name> <path>] ...
                           add a group of alternatives to the system.
argument explanation
link 실행파일(Short cut)이 위치하는 곳, gcc의 경우 /usr/bin/gcc
name package를 대표할 수 있는 이름
path short cut을 실제 연결할 link, gcc-7의 경우 /usr/bin/gcc-7
priority automatic mode에서 우선 순위를 임의의 숫자로 표현

 

gcc에 대해서 세팅을 해보자. gcc-7을 priority 700으로 (참고로, priority가 높을 수록 우선 순위를 가져간다)

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 120

update-alternatives --display gcc
gcc - auto mode
  link best version is /usr/bin/gcc-7
  link currently points to /usr/bin/gcc-7
  link gcc is /usr/bin/gcc
/usr/bin/gcc-12 - priority 120
/usr/bin/gcc-7 - priority 700

이제 프롬프트에서 버젼을 확인해 보자

gcc --version
gcc (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

같은 작업을 g++에 대해서도 해보자

g++ --version
g++ (Ubuntu 12.2.0-3ubuntu1) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

dpkg -l | grep g++
ii  g++                                        4:12.2.0-1ubuntu1                        amd64        GNU C++ compiler
ii  g++-12                                     12.2.0-3ubuntu1                          amd64        GNU C++ compiler
ii  g++-7                                      7.5.0-6ubuntu2                           amd64        GNU C++ compiler

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 700
update-alternatives: using /usr/bin/g++-7 to provide /usr/bin/g++ (g++) in auto mode
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 120

update-alternatives --display g++
g++ - auto mode
  link best version is /usr/bin/g++-7
  link currently points to /usr/bin/g++-7
  link g++ is /usr/bin/g++
/usr/bin/g++-12 - priority 120
/usr/bin/g++-7 - priority 700

g++ --version
g++ (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

자.. 이제 기도 한번 하고 컴파일 해보자고!

'OpenFOAM' 카테고리의 다른 글

BlockMesh 생성하기  (1) 2024.01.03
OpenFOAM의 기본 구조 및 실행순서  (1) 2023.12.26
GCC Version  (0) 2023.08.13
CFD-DEM  (0) 2023.08.12