Ubuntu 22.04 LTSにプログラミング言語Fortranをインストールする

環境

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04 LTS"

プログラミング言語Fortranのインストール手順
1.リポジトリを追加します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test

2.システムパッケージを更新します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt update
# sudo apt update
# sudo apt update

3.Fortranをインストールします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# sudo apt install gfortran-9
# sudo apt install gfortran-9
# sudo apt install gfortran-9

Fortranバージョンを確認します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# gfortran-9 --version
GNU Fortran (Ubuntu 9.4.0-5ubuntu1) 9.4.0
Copyright (C) 2019 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.
# gfortran-9 --version GNU Fortran (Ubuntu 9.4.0-5ubuntu1) 9.4.0 Copyright (C) 2019 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.
# gfortran-9 --version
GNU Fortran (Ubuntu 9.4.0-5ubuntu1) 9.4.0
Copyright (C) 2019 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.

4.動作確認
# nano test.f90
以下の内容を編集します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PROGRAM HELLO
PRINT *, 'Hello, World! study skill'
END PROGRAM HELLO
PROGRAM HELLO PRINT *, 'Hello, World! study skill' END PROGRAM HELLO
PROGRAM HELLO
PRINT *, 'Hello, World! study skill'
END PROGRAM HELLO

5.ファイルをコンパイルします

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# gfortran-9 -o test test.f90
# gfortran-9 -o test test.f90
# gfortran-9 -o test test.f90

ファイルを実行します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# ./test
Hello, World! study skill
# ./test Hello, World! study skill
# ./test
Hello, World! study skill

 

Ubuntu 22.04

Posted by arkgame