> 시스템 튜토리얼 > 리눅스 > 명령-창립 : Linux에서 사용할 수없는 명령에 대한 패키지 설치 제안

명령-창립 : Linux에서 사용할 수없는 명령에 대한 패키지 설치 제안

Lisa Kudrow
풀어 주다: 2025-03-22 09:58:14
원래의
712명이 탐색했습니다.

As you may already know, when we run an unavailable or unrecognized command in Linux, we will get an error message - "bash: command not found". The problem is some of us don't know which packages provides that particular command. Not anymore! Today, I've come across an useful utility called "command-not-found" that helps you by suggesting installation of packages when running an unavailable command in Linux.

For instance, let us say you want to run a command named "leafpad", which is not available in your Linux system. You are not sure which packages provides this command. This is where "command-not-found" utility comes in help.

The command-not-found utility will automatically search the official repositories, when entering an unrecognized or unavailable command. It uses a cache of existing programs and their associated packages to help users in their day-to-day command line work.

Install command-not-found Utility in Linux

The 'command-not-found' utility is available in AUR. So, you can install it using AUR helpers such as Paru or Yay.

$ paru -S command-not-found
로그인 후 복사

Or,

$ yay -S command-not-found
로그인 후 복사

Also, pkgfile package provides command-not-found hook. Just install pkgfile to use command-not-found utility.

$ sudo pacman -S pkgfile
로그인 후 복사

Once it is installed, edit your .bashrc file:

$ vi ~/.bashrc
로그인 후 복사

Add the following line at the end to enable it.

source /usr/share/doc/pkgfile/command-not-found.bash
로그인 후 복사

Update the changes made using command:

$ source ~/.bashrc
로그인 후 복사

On Ubuntu and its derivatives, it comes pre-installed.

Just in case if it is not installed already, you can install it as follows.

$ sudo apt update
$ sudo apt install command-not-found
로그인 후 복사

The system-wide cache is empty. You may want to run 'apt-file update' as root to update the cache.

After installing it, you may need to run the following commands as root to update the system-wide cache.

$ sudo update-command-not-found
$ sudo apt-file update
로그인 후 복사

Suggest Package Installation When Command Not Found in Linux

Now, run any unavailable command, for example leafpad:

It will suggest you which package provides this command. Here is the output from my Arch Linux system.

<strong>$ leafpad</strong> 
Command 'leafpad' not found, but can be installed with:
sudo snap install leafpad
로그인 후 복사

As you see in the above output, the "leafpad" command is provided by leafpad-0.8.18.1-5 package.

Let us try another command on Ubuntu:

<strong>$ emacs</strong>
The program 'emacs' can be found in the following packages:
 * emacs24
 * emacs24-nox
 * e3
 * emacs23
 * emacs23-lucid
 * emacs23-nox
 * emacs24-lucid
 * jove
Try: sudo apt-get install <selected package>
로그인 후 복사

명령-창립 : Linux에서 사용할 수없는 명령에 대한 패키지 설치 제안

This is just an example. This utility will suggest installation of packages when you run any unavailable command. Once you removed this utility, it won't suggest anything. It will simply display an output something like below.

"bash: emacs: command not found"
로그인 후 복사

Hope this helps.

위 내용은 명령-창립 : Linux에서 사용할 수없는 명령에 대한 패키지 설치 제안의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿