ソースファイルインストールしたものをアンインストール(make uninstall)するには

HOMELinux技術 リナックスマスター.JP(Linuxマスター.JP)Linuxtips, インストール > ソースファイルインストールしたものをアンインストール(make uninstall)するには

無料Linux入門マニュアル無料ダウンロード

今だけ2,200円のLinux入門PDFマニュアルが【数量限定】で無料ダウンロードできます。
Linux入門マニュアル無料ダウンロードはこちらをクリック

ソースファイル、ソースコード(tar.gz)でインストールしたソフトは、
「make uninstall」で削除できます。
しかし、すべてのソフトウェアが「make uninstall」に対応していて、
削除出来るわけではなく、むしろ削除できない方が多いのです。

「make uninstall」は、実行ファイルを削除しているに過ぎないので、
手作業で同じ作業を行うことで「make uninstall」に対応していない
ソフトウェアのアンインストールが可能になります。

どちらの実行にもroot(スーパーユーザー)権限が必要になります。

make uninstallでアンインストールする

$ su -   ←root権限になります。 パスワード:         ←rootパスワードを入力します(入力するパスワードは表示されません) # /usr/local/pgsql/bin/psql -V ←バージョンを確認します。 psql (PostgreSQL) 10.5 # systemctl stop postgresql.service ←PostgreSQLを停止します。 # cd /usr/local/src/postgresql-10.5/ ←ソースファイルを展開しているディレクトリに移動します。 # make uninstall ←make uninstallでアンインストールを実行します。 make -C doc uninstall make[1]: ディレクトリ `/usr/local/src/postgresql-10.5/doc' に入ります make -C src uninstall make[2]: ディレクトリ `/usr/local/src/postgresql-10.5/doc/src' に入ります make -C sgml uninstall make[3]: ディレクトリ `/usr/local/src/postgresql-10.5/doc/src/sgml' に入ります rm -f '/usr/local/pgsql/share/doc//html/'* '/usr/local/pgsql/share/man'/man1/* '/usr/local/pgsql/share/man'/man3/* ' /usr/local/pgsql/share/man'/man7/* make[3]: ディレクトリ `/usr/local/src/postgresql-10.5/doc/src/sgml' から出ます make[2]: ディレクトリ `/usr/local/src/postgresql-10.5/doc/src' から出ます make[1]: ディレクトリ `/usr/local/src/postgresql-10.5/doc' から出ます make -C src uninstall 〜中略〜 rm -f '/usr/local/pgsql/lib/pgxs/src'/Makefile.global '/usr/local/pgsql/lib/pgxs/src' /Makefile.port '/usr/local/pgsql/lib/pgxs/src' /Makefile.shlib '/usr/local/pgsql/lib/pgxs/src'/nls-global.mk make[1]: ディレクトリ `/usr/local/src/postgresql-10.5/src' から出ます make -C config uninstall make[1]: ディレクトリ `/usr/local/src/postgresql-10.5/config' に入ります rm -f '/usr/local/pgsql/lib/pgxs/config/install-sh' rm -f '/usr/local/pgsql/lib/pgxs/config/missing' make[1]: ディレクトリ `/usr/local/src/postgresql-10.5/config' から出ます




make uninstallでアンインストールしてもディレクトリは残る

make uninstallでアンインストールしてもディレクトリは残ります。

# ls -l /usr/local/pgsql 合計 4 drwxr-xr-x 2 root root 6 1月 28 12:43 bin drwx------ 19 postgres root 4096 1月 28 12:35 data drwxr-xr-x 6 root root 65 1月 28 12:43 include drwxr-xr-x 4 root root 35 1月 28 12:43 lib drwxr-xr-x 4 root root 43 1月 28 12:43 share


make uninstallでもPostgreSQLデータは残ったまま

実行ファイル等は削除されても、データは削除されない。
再インストールすれば、再利用できる?

# ls -l /usr/local/pgsql/data/ 合計 56 -rw------- 1 postgres postgres 3 1月 24 2019 PG_VERSION drwx------ 6 postgres postgres 54 1月 25 2019 base drwx------ 2 postgres postgres 4096 1月 28 12:36 global drwx------ 2 postgres postgres 6 1月 24 2019 pg_commit_ts drwx------ 2 postgres postgres 6 1月 24 2019 pg_dynshmem -rw------- 1 postgres postgres 4513 1月 24 2019 pg_hba.conf -rw------- 1 postgres postgres 1636 1月 24 2019 pg_ident.conf drwx------ 4 postgres postgres 68 1月 28 12:40 pg_logical drwx------ 4 postgres postgres 36 1月 24 2019 pg_multixact drwx------ 2 postgres postgres 18 1月 28 12:35 pg_notify drwx------ 2 postgres postgres 6 1月 24 2019 pg_replslot drwx------ 2 postgres postgres 6 1月 24 2019 pg_serial drwx------ 2 postgres postgres 6 1月 24 2019 pg_snapshots drwx------ 2 postgres postgres 6 1月 28 12:35 pg_stat drwx------ 2 postgres postgres 84 1月 28 12:45 pg_stat_tmp drwx------ 2 postgres postgres 18 1月 24 2019 pg_subtrans drwx------ 2 postgres postgres 6 1月 24 2019 pg_tblspc drwx------ 2 postgres postgres 6 1月 24 2019 pg_twophase drwx------ 3 postgres postgres 60 1月 24 2019 pg_wal drwx------ 2 postgres postgres 18 1月 24 2019 pg_xact -rw------- 1 postgres postgres 88 1月 24 2019 postgresql.auto.conf -rw------- 1 postgres postgres 22791 1月 24 2019 postgresql.conf -rw------- 1 postgres postgres 59 1月 28 12:35 postmaster.opts -rw------- 1 postgres postgres 87 1月 28 12:35 postmaster.pid


make uninstallでアンインストール後処理

# /usr/local/pgsql/bin/psql -V ←バージョンを確認します。 -bash: /usr/local/pgsql/bin/psql: そのようなファイルやディレクトリはありません ↑実行ファイルが削除されているので、エラーになります。


PostgreSQLのサービス登録を削除します。

# systemctl disable postgresql.service Removed symlink /etc/systemd/system/multi-user.target.wants/postgresql.service.


データなどが必要ない場合、PostgreSQLのインストールディレクトリを削除します。

# rm -rf /usr/local/pgsql/


make uninstallでアンインストール出来ない場合

make uninstallでアンインストール出来ない場合、下記エラーが表示されます。
MySQL、Apache、Proftpd、PHP7がアンインストールできませんでした。

[root@Tiger mysql-5.7.24]# make uninstall make: *** ターゲット `uninstall' を make するルールがありません. 中止. [root@Tiger httpd-2.4.37]# make uninstall make: *** ターゲット `uninstall' を make するルールがありません. 中止. [root@Tiger proftpd-1.3.6]# make uninstall make: *** ターゲット `uninstall' を make するルールがありません. 中止. [root@Tiger php-7.3.1]# make uninstall make: *** ターゲット `uninstall' を make するルールがありません. 中止.


ソースファイルを手作業でアンインストールする

make uninstallが使用できず、それでもアンインストールしたい場合は手作業で削除します。
今回の例では、Apacheを使用します。
作業の流れとしては、tmpディレクトリにApacheを仮インストールし、
そのインストールされたファイルリストをもとに実際にインストールされている
Apacheファイルを削除します。

# cd /usr/local/src/httpd-2.4.37/ ←ソースファイルを展開しているディレクトリに移動します。 # /usr/local/apache2/bin/apachectl -v ←Apacheのバージョンを確認します。 Server version: Apache/2.4.37 (Unix) Server built: Feb 22 2019 18:29:42 # systemctl stop httpd.service ←Apacheを停止します。 # mkdir /tmp/apache2-install-test ←仮インストールするディレクトリを作成します。 # make install DESTDIR=/tmp/apache2-install-test ←仮インストールします。 # find /tmp/apache2-install-test -type f -print > /tmp/apache2-install-test.txt ↑インストールしたファイル一覧を/tmp/apache2-install-test.txtに保存します。


/tmp/apache2-install-test.txtファイルの内容

/tmp/apache2-install-test/usr/local/apache2/lib/pkgconfig/apr-1.pc /tmp/apache2-install-test/usr/local/apache2/lib/pkgconfig/apr-util-1.pc /tmp/apache2-install-test/usr/local/apache2/lib/libapr-1.so.0.6.3 /tmp/apache2-install-test/usr/local/apache2/lib/libapr-1.la /tmp/apache2-install-test/usr/local/apache2/lib/libapr-1.a /tmp/apache2-install-test/usr/local/apache2/lib/apr.exp /tmp/apache2-install-test/usr/local/apache2/lib/libaprutil-1.so.0.6.1 /tmp/apache2-install-test/usr/local/apache2/lib/libaprutil-1.la /tmp/apache2-install-test/usr/local/apache2/lib/libaprutil-1.a


ファイルパスを/tmpから/usr/localに置換します。
viエディタを起動し、置換処理を行います。

# vi /tmp/apache2-install-test.txt


vi起動後、下記コマンドを実行します。

:%s/\/tmp\/apache2-install-test//g


置換後、ファイルパスが/usr/localに置換されます。

/usr/local/apache2/lib/pkgconfig/apr-1.pc /usr/local/apache2/lib/pkgconfig/apr-util-1.pc /usr/local/apache2/lib/libapr-1.so.0.6.3 /usr/local/apache2/lib/libapr-1.la /usr/local/apache2/lib/libapr-1.a /usr/local/apache2/lib/apr.exp /usr/local/apache2/lib/libaprutil-1.so.0.6.1 /usr/local/apache2/lib/libaprutil-1.la /usr/local/apache2/lib/libaprutil-1.a /usr/local/apache2/lib/aprutil.exp /usr/local/apache2/bin/apr-1-config


置換完了後「:wq」でviを終了します。

ちなみに、sedコマンドでも編集可能です。
下記例では「/tmp/apache2-install-test2.txt」ファイルに結果を保存します。

# sed -e "s/\/tmp\/apache2-install-test//g" /tmp/apache2-install-test.txt > /tmp/apache2-install-test2.txt /usr/local/apache2/lib/pkgconfig/apr-1.pc /usr/local/apache2/lib/pkgconfig/apr-util-1.pc /usr/local/apache2/lib/libapr-1.so.0.6.3 /usr/local/apache2/lib/libapr-1.la /usr/local/apache2/lib/libapr-1.a /usr/local/apache2/lib/apr.exp /usr/local/apache2/lib/libaprutil-1.so.0.6.1 /usr/local/apache2/lib/libaprutil-1.la /usr/local/apache2/lib/libaprutil-1.a /usr/local/apache2/lib/aprutil.exp /usr/local/apache2/bin/apr-1-config /usr/local/apache2/bin/apu-1-config /usr/local/apache2/bin/htpasswd /usr/local/apache2/bin/htdigest /usr/local/apache2/bin/htdbm


置換したリストを元にApacheのインストールファイルを削除します。

# cat /tmp/apache2-install-test.txt | xargs rm -f


削除後のバージョン確認をします。
実行ファイルが削除されたので、エラーになります。

# /usr/local/apache2/bin/apachectl -v -bash: /usr/local/apache2/bin/apachectl: そのようなファイルやディレクトリはありません


この作業でもインストールディレクトリは残ります。

# ls -l /usr/local/apache2/ 合計 0 drwxr-xr-x 2 root root 6 1月 28 12:48 bin drwxr-xr-x 2 root root 6 1月 28 12:48 build drwxr-xr-x 2 root root 6 1月 28 12:48 cgi-bin drwxr-xr-x 4 root root 57 1月 28 12:48 conf drwxr-xr-x 3 root root 21 1月 28 12:48 error drwxr-sr-x 2 root root 6 1月 28 12:48 htdocs drwxr-xr-x 3 root root 19 1月 28 12:48 icons drwxr-xr-x 2 root root 6 1月 28 12:48 include drwxr-xr-x 3 root root 111 1月 28 12:48 lib drwxr-xr-x 2 root root 85 1月 28 12:35 logs drwxr-xr-x 4 root root 30 1月 24 2019 man drwxr-sr-x 14 root root 169 1月 28 12:48 manual drwxr-xr-x 2 root root 6 1月 28 12:48 modules


ディレクトリが不要な場合は削除します。

# rm -rf /usr/local/apache2/


Apacheのサービス登録を削除します。

# systemctl disable httpd.service Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.


tmpディレクトリのapache2-install-test、apache2-install-test.txtも削除します。

# rm -rf /tmp/apache2-install-test*


以上で手作業でのソースファイルのアンインストールは完了です。


無料Linux入門マニュアル無料ダウンロード

今だけ2,200円のLinux入門PDFマニュアルが【数量限定】で無料ダウンロードできます。
Linux入門マニュアル無料ダウンロードはこちらをクリック


<<関連記事>>
・MIMEでエンコードされたテキストを読めるように変換する
・viエディタで文字をコピーする
・ハードディスクの使用状況を調べるには
・tar.bz2ファイルを解凍して展開するには
・tar.gz形式のファイルを解凍、展開するには

Linux入門マニュアル無料ダウンロード