构建基础包的基础知识
构建 编译
![](/data/attachment/album/202111/05/113250t7q20dqqzdgges05.png)



> 
> 这是一篇快速提示，旨在给 Ubuntu 的新用户解释构建基础包是什么、它的用处和安装步骤。
> 
> 
> 


在 Ubuntu 中安装构建基础包（`build-essential`），只需要在终端中简单输入这个命令：



```
sudo apt update && sudo apt install build-essential

```

但围绕它有几个问题，你可能想知道答案：


* 什么是构建基础包？
* 它包含什么内容？
* 为什么要安装它（如果安装的话）？
* 如何安装它？
* 如何删除它？


### 什么是 Ubuntu 中的构建基础包？


构建基础包（`build-essential`）实际上是属于 Debian 的。在它里面其实并不是一个软件。它包含了创建一个 Debian 包（`.deb`）所需的软件包列表。这些软件包包括 `libc`、`gcc`、`g++`、`make`、`dpkg-dev` 等。构建基础包包含这些所需的软件包作为依赖，所以当你安装它时，你只需一个命令就能安装所有这些软件包。


请不要认为构建基础包是一个可以在一个命令中神奇地安装从 Ruby 到 Go 的所有开发工具的超级软件包。它包含一些开发工具，但不是全部。


#### 你为什么要安装构建基础包？


它用来从应用的源代码创建 DEB 包。一个普通用户不会每天都去创建 DEB 包，对吗？


然而，有些用户可能会使用他们的 Ubuntu Linux 系统进行软件开发。如果你想 [在 Ubuntu 中运行 c 程序](https://itsfoss.com/run-c-program-linux/)，你需要 gcc 编译器。如果你想 [在 Ubuntu 中运行 C++ 程序](https://itsfoss.com/c-plus-plus-ubuntu/)，你需要 g++ 编译器。如果你要使用一个不寻常的、只能从源代码中获得的软件，你的系统会抛出 “[make 命令未找到的错误](https://itsfoss.com/make-command-not-found-ubuntu/)”，因为你需要先安装 `make` 工具。


当然，所有这些都可以单独安装。然而，利用构建基础包的优势，一次性安装所有这些开发工具要容易得多。这就是你得到的好处。


这就像 [ubuntu-restricted-extras 包允许你一次安装几个媒体编解码器](https://itsfoss.com/install-media-codecs-ubuntu/)。


现在你知道了这个包的好处，让我们看看如何安装它。


### 在 Ubuntu Linux 中安装构建基础包


在 Ubuntu 中按 `Ctrl+Alt+T` 快捷键打开终端，输入以下命令：



```
sudo apt update

```

使用 `sudo` 命令，你会被要求输入你的账户密码。当你输入时，屏幕上没有任何显示。这没问题。这在大多数 Linux 系统中都是这样的。盲打输入你的密码，然后按回车键。


![](/data/attachment/album/202111/05/113252lrl36w1z6p1zowoz.png)


`apt update` 命令刷新了本地软件包的缓存。这对于一个新安装的 Ubuntu 来说是必不可少的。


之后，运行下面的命令来安装构建基础包：



```
sudo apt install build-essential

```

它应该显示所有要安装的软件包。当要求确认时按 `Y`：


![](/data/attachment/album/202111/05/113253nnns3nwvpvp3wy03.png)


等待安装完成。就好了。


### 从 Ubuntu 中删除构建基础包


保留这些开发工具不会损害你的系统。但如果你的磁盘空间不足，你可以考虑删除它。


在 Ubuntu 中，由于有 `apt remove` 命令，删除软件很容易：



```
sudo apt remove build-essential

```

运行 `autoremove` 命令来删除剩余的依赖包也是一个好主意：



```
sudo apt autoremove

```

你现在知道了所有关于构建基础包的基础（双关语）。请享受它吧~




---


via: <https://itsfoss.com/build-essential-ubuntu/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Installing build-essential package in Ubuntu is as simple as typing this command in the terminal:

`sudo apt update && sudo apt install build-essential`


But there are several questions around it that you may want answers to:

- What is build essential package?
- What does it contain?
- Why should you install it (if install at all)?
- How to install it?
- How to remove it?

## What is build-essential package in Ubuntu?

The build-essential package actually belongs to Debian. It is not a piece of software in itself. It contains a list of packages that are required to create a Debian package (deb). These packages are libc, gcc, g++, make, dpkg-dev etc. The build-essential package contains those required packages as dependencies, so when you install build-essential, you install all those packages in one single command.

Please do NOT consider build-essential to be a super package that will magically install all kind of development tools from Ruby to Go for you in a single command. It has some development tool but not all.

### Why would you want to install build-essential package?

It is used for creating DEB packages from the source code of an application. An average user does not go around creating DEB packages everyday, right?

However, some users may use their Ubuntu Linux system for software development. You want to [run c program in Ubuntu](https://itsfoss.com/run-c-program-linux/), you need gcc compiler. You want to [run C++ programs in Ubuntu](https://itsfoss.com/c-plus-plus-ubuntu/), you need g++ compiler. If you have to use an unusual software that is only available from the source code, your system will throw [make command not found error](https://itsfoss.com/make-command-not-found-ubuntu/) because you need to install make tool first.

All this can be installed individually, of course. However, it is much easier to take advantage of the build-essential package and install all these development tools at once. That’s the benefit you get.

It is like the [ubuntu-restricted-extras package that allows you to install several media codecs](https://itsfoss.com/install-media-codecs-ubuntu/) at once.

Now that you know the advantage of this package, let’s see how to install it.

## Installing build-essential package in Ubuntu Linux

![build essential ubuntu](https://itsfoss.com/content/images/wordpress/2021/10/Build-Essential-Ubuntu.png)

Open a terminal in Ubuntu by pressing the Ctrl+Alt+T shortcut and enter the following command:

`sudo apt update`


With sudo command, you’ll be asked to enter your account’s password. When you type it, nothing is displayed on the screen. That is fine. That’s how it works in most Linux systems. Type your password blindly and press enter.

![apt update](https://itsfoss.com/content/images/wordpress/2021/10/apt-update-800x467.png)

The apt update command refreshes the local package cache. This is essential for a fresh Ubuntu install.

After that, run the following command to install build-essential tool:

`sudo apt install build-essential`


It should show all the packages it is going to install. Press Y when asked for confirmation:

![install build essential ubuntu](https://itsfoss.com/content/images/wordpress/2021/10/install-build-essential-ubuntu-800x434.png)

Wait a bit for the installation to complete. That’s it.

## Removing build-essential tool from Ubuntu

Keeping those development tools won’t harm your system. but if you are running low on the disk space, you may consider removing it.

Removing software is easy in Ubuntu thanks to the apt remove command:

`sudo apt remove build-essential`


It will be a good idea to run the autoremove command to remove the residual dependency packages as well:

`sudo apt autoremove`


You know all the essential about build-essential package now (pun intended). Enjoy it :)