개요
안녕하세요 피터입니다.
Linux에 개발환경을 구축하기 위해서는 컴파일러(Compiler) 설치가 필수입니다.
C언어 컴파일러는 gcc, C++언어 컴파일러는 g++ 인데 OS 설치 시 최소설치(Minimum)으로 설치한 경우 설치가 안되어 있는 경우가 있습니다.
이런 경우 리눅스에서 제공하는 yum이라는 패키지 관리 도구를 이용해서 쉽게 설치할 수 있습니다.
gcc 설치
yum을 이용해 아래 명령어로 설치해줍니다.
yum install gcc
[root@peterdev test]# yum install gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: mirror.dmmlabs.jp
* extras: ftp.tsukuba.wide.ad.jp
* ius: mirrors.kernel.org
* updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-28.el7 will be installed
--> Processing Dependency: libgomp = 4.8.5-28.el7 for package: gcc-4.8.5-28.el7.x86_64
--> Processing Dependency: cpp = 4.8.5-28.el7 for package: gcc-4.8.5-28.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-28.el7 for package: gcc-4.8.5-28.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-28.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-28.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-28.el7.x86_64
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-28.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: glibc-headers = 2.17-222.el7 for package: glibc-devel-2.17-222.el7.x86_64
--> Processing Dependency: glibc = 2.17-222.el7 for package: glibc-devel-2.17-222.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-222.el7.x86_64
---> Package libgcc.x86_64 0:4.8.5-16.el7_4.2 will be updated
---> Package libgcc.x86_64 0:4.8.5-28.el7 will be an update
---> Package libgomp.x86_64 0:4.8.5-16.el7_4.2 will be updated
---> Package libgomp.x86_64 0:4.8.5-28.el7 will be an update
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.17-196.el7_4.2 will be updated
--> Processing Dependency: glibc = 2.17-196.el7_4.2 for package: glibc-common-2.17-196.el7_4.2.x86_64
---> Package glibc.x86_64 0:2.17-222.el7 will be an update
---> Package glibc-headers.x86_64 0:2.17-222.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-222.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-222.el7.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-196.el7_4.2 will be updated
---> Package glibc-common.x86_64 0:2.17-222.el7 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-862.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
gcc x86_64 4.8.5-28.el7 base 16 M
Installing for dependencies:
cpp x86_64 4.8.5-28.el7 base 5.9 M
glibc-devel x86_64 2.17-222.el7 base 1.1 M
glibc-headers x86_64 2.17-222.el7 base 678 k
kernel-headers x86_64 3.10.0-862.el7 base 7.1 M
libmpc x86_64 1.0.1-3.el7 base 51 k
mpfr x86_64 3.1.1-4.el7 base 203 k
Updating for dependencies:
glibc x86_64 2.17-222.el7 base 3.6 M
glibc-common x86_64 2.17-222.el7 base 11 M
libgcc x86_64 4.8.5-28.el7 base 101 k
libgomp x86_64 4.8.5-28.el7 base 156 k
Transaction Summary
===============================================================================
Install 1 Package (+6 Dependent packages)
Upgrade ( 4 Dependent packages)
Total download size: 47 M
Is this ok [y/d/N]: y
gcc를 사용하기 위해서는 보시는바와 같이 glibc-devel, kernel-headers 등과 같이 필수적으로 요구되는 rpm 들이 존재합니다. yum을 이용하면 이러한 의존성(dependency) 자동으로 추적하여 관련된 rpm들을 한번에 설치해주기 때문에 개별적으로 설치하는 것에 비해 굉장히 편리합니다.
일부는 새로 설치되고 일부는 업데이트 되는군요.
y 를 누르고 계속 진행합니다.
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/11): cpp-4.8.5-28.el7.x86_64.rpm | 5.9 MB 00:01
(2/11): glibc-2.17-222.el7.x86_64.rpm | 3.6 MB 00:01
(3/11): gcc-4.8.5-28.el7.x86_64.rpm | 16 MB 00:06
(4/11): glibc-devel-2.17-222.el7.x86_64.rpm | 1.1 MB 00:00
(5/11): glibc-headers-2.17-222.el7.x86_64.rpm | 678 kB 00:00
(6/11): glibc-common-2.17-222.el7.x86_64.rpm | 11 MB 00:04
(7/11): libgcc-4.8.5-28.el7.x86_64.rpm | 101 kB 00:00
(8/11): libgomp-4.8.5-28.el7.x86_64.rpm | 156 kB 00:00
(9/11): libmpc-1.0.1-3.el7.x86_64.rpm | 51 kB 00:00
(10/11): mpfr-3.1.1-4.el7.x86_64.rpm | 203 kB 00:00
(11/11): kernel-headers-3.10.0-862.el7.x86_64.rpm | 7.1 MB 00:02
-------------------------------------------------------------------------------
Total 4.5 MB/s | 47 MB 00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libgcc-4.8.5-28.el7.x86_64 1/15
Updating : glibc-2.17-222.el7.x86_64 2/15
Updating : glibc-common-2.17-222.el7.x86_64 3/15
Installing : mpfr-3.1.1-4.el7.x86_64 4/15
Installing : libmpc-1.0.1-3.el7.x86_64 5/15
Installing : cpp-4.8.5-28.el7.x86_64 6/15
Updating : libgomp-4.8.5-28.el7.x86_64 7/15
Installing : kernel-headers-3.10.0-862.el7.x86_64 8/15
Installing : glibc-headers-2.17-222.el7.x86_64 9/15
Installing : glibc-devel-2.17-222.el7.x86_64 10/15
Installing : gcc-4.8.5-28.el7.x86_64 11/15
Cleanup : libgomp-4.8.5-16.el7_4.2.x86_64 12/15
Cleanup : glibc-common-2.17-196.el7_4.2.x86_64 13/15
Cleanup : glibc-2.17-196.el7_4.2.x86_64 14/15
Cleanup : libgcc-4.8.5-16.el7_4.2.x86_64 15/15
Verifying : gcc-4.8.5-28.el7.x86_64 1/15
Verifying : cpp-4.8.5-28.el7.x86_64 2/15
Verifying : libgomp-4.8.5-28.el7.x86_64 3/15
Verifying : glibc-headers-2.17-222.el7.x86_64 4/15
Verifying : glibc-devel-2.17-222.el7.x86_64 5/15
Verifying : kernel-headers-3.10.0-862.el7.x86_64 6/15
Verifying : mpfr-3.1.1-4.el7.x86_64 7/15
Verifying : libmpc-1.0.1-3.el7.x86_64 8/15
Verifying : glibc-common-2.17-222.el7.x86_64 9/15
Verifying : glibc-2.17-222.el7.x86_64 10/15
Verifying : libgcc-4.8.5-28.el7.x86_64 11/15
Verifying : libgcc-4.8.5-16.el7_4.2.x86_64 12/15
Verifying : glibc-common-2.17-196.el7_4.2.x86_64 13/15
Verifying : libgomp-4.8.5-16.el7_4.2.x86_64 14/15
Verifying : glibc-2.17-196.el7_4.2.x86_64 15/15
Installed:
gcc.x86_64 0:4.8.5-28.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-28.el7 glibc-devel.x86_64 0:2.17-222.el7
glibc-headers.x86_64 0:2.17-222.el7 kernel-headers.x86_64 0:3.10.0-862.el7
libmpc.x86_64 0:1.0.1-3.el7 mpfr.x86_64 0:3.1.1-4.el7
Dependency Updated:
glibc.x86_64 0:2.17-222.el7 glibc-common.x86_64 0:2.17-222.el7
libgcc.x86_64 0:4.8.5-28.el7 libgomp.x86_64 0:4.8.5-28.el7
Complete!
자 이제 설치가 끝났습니다.
아래 명령어로 정상적으로 실행되는지 확인해봅니다.
gcc --version
[root@peterdev test]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Copyright (C) 2015 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++ 설치
yum install gcc-c++
[root@peterdev test]# yum install gcc-c++
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* epel: mirror.dmmlabs.jp
* extras: ftp.tsukuba.wide.ad.jp
* ius: mirrors.kernel.org
* updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-28.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-28.el7 for package: gcc-c++-4.8.5-28.el7.x86_64
--> Processing Dependency: libstdc++ = 4.8.5-28.el7 for package: gcc-c++-4.8.5-28.el7.x86_64
--> Running transaction check
---> Package libstdc++.x86_64 0:4.8.5-16.el7_4.2 will be updated
---> Package libstdc++.x86_64 0:4.8.5-28.el7 will be an update
---> Package libstdc++-devel.x86_64 0:4.8.5-28.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
gcc-c++ x86_64 4.8.5-28.el7 base 7.2 M
Installing for dependencies:
libstdc++-devel x86_64 4.8.5-28.el7 base 1.5 M
Updating for dependencies:
libstdc++ x86_64 4.8.5-28.el7 base 304 k
Transaction Summary
===============================================================================
Install 1 Package (+1 Dependent package)
Upgrade ( 1 Dependent package)
Total download size: 9.0 M
Is this ok [y/d/N]: y
확인 한 다음 마찬가지로 y를 입력하여 진행합니다.
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): libstdc++-4.8.5-28.el7.x86_64.rpm | 304 kB 00:00
(2/3): libstdc++-devel-4.8.5-28.el7.x86_64.rpm | 1.5 MB 00:00
(3/3): gcc-c++-4.8.5-28.el7.x86_64.rpm | 7.2 MB 00:03
-------------------------------------------------------------------------------
Total 2.2 MB/s | 9.0 MB 00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : libstdc++-4.8.5-28.el7.x86_64 1/4
Installing : libstdc++-devel-4.8.5-28.el7.x86_64 2/4
Installing : gcc-c++-4.8.5-28.el7.x86_64 3/4
Cleanup : libstdc++-4.8.5-16.el7_4.2.x86_64 4/4
Verifying : libstdc++-4.8.5-28.el7.x86_64 1/4
Verifying : libstdc++-devel-4.8.5-28.el7.x86_64 2/4
Verifying : gcc-c++-4.8.5-28.el7.x86_64 3/4
Verifying : libstdc++-4.8.5-16.el7_4.2.x86_64 4/4
Installed:
gcc-c++.x86_64 0:4.8.5-28.el7
Dependency Installed:
libstdc++-devel.x86_64 0:4.8.5-28.el7
Dependency Updated:
libstdc++.x86_64 0:4.8.5-28.el7
Complete!
설치가 완료되면 정상적으로 설치되었는지 확인해봅니다.
g++ --version
[root@peterdev test]# g++ --version
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Copyright (C) 2015 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.
번외
yum으로 설치하는 과정에서 y 입력하는 것이 귀찮다면 아래와 같이 -y 옵션을 사용하면 y를 입력한 것과 같이 자동으로 설치가 진행됩니다.
yum -y install gcc
yum -y install gcc-c++
여러분의 댓글은 저에게 크나큰 힘이 됩니다. 오류 및 의견 주시면 감사하겠습니다.
-Peter의 우아한 프로그래밍
'OS > Linux' 카테고리의 다른 글
[Linux] rdate로 시간동기화 하기 (0) | 2018.05.18 |
---|---|
[Linux] 파이프(pipe)에 대한 이해 (7) | 2018.05.15 |
[Linux] touch 파일 생성하기 (0) | 2018.05.09 |
[Linux] mv 파일 및 디렉토리 이동 (0) | 2018.05.09 |
[Linux] find 로 파일 찾아서 지우기 (5) | 2018.05.08 |