【Ubuntu】sudoコマンドがない場合の対処法

【Ubuntu】sudoコマンドがない場合の対処法

Ubuntuにsudoコマンドがない場合は、apt installコマンドでインストールを行います。

Ubuntuでsudoコマンドがない場合は、aptでインストールします。

確認した環境

Ubuntu 24.04 LTS

sudoコマンドがない

以下コマンドを実行。

sudo apt update

sudoが無くてエラーとなった。

bash: sudo: command not found

rootにスイッチ

rootユーザでない場合、以下コマンドでrootになる。

su - root

パッケージを更新する

事前にパッケージを更新しておく。

apt update

aptでsudoを検索

以下コマンドでsudoパッケージを検索。

apt search sudo

出力例。


sudo/noble 1.9.15p5-3ubuntu5 amd64
  Provide limited super user privileges to specific users

sudoをインストール

以下コマンドでsudoをインストールする。

apt install sudo

出力例。

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  sudo
0 upgraded, 1 newly installed, 0 to remove and 19 not upgraded.
Need to get 948 kB of archives.
After this operation, 3547 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 sudo amd64 1.9.15p5-3ubuntu5 [948 kB]
Fetched 948 kB in 6s (164 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package sudo.
(Reading database ... 50796 files and directories currently installed.)
Preparing to unpack .../sudo_1.9.15p5-3ubuntu5_amd64.deb ...
Unpacking sudo (1.9.15p5-3ubuntu5) ...
Setting up sudo (1.9.15p5-3ubuntu5) ...
Processing triggers for libc-bin (2.39-0ubuntu8.2) ...

sudo実行確認

sudoが実行できることを確認する。

sudo apt update

出力例

$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu noble-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu noble InRelease
Hit:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu noble-backports InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
19 packages can be upgraded. Run 'apt list --upgradable' to see them.

以上です。
よいITライフを。