如何在 Ubuntu Linux 上安装 Code Blocks IDE
IDE
![](/data/attachment/album/202106/14/164807ov99wdi2m7pmgz2j.jpg)


Code Blocks 是一个用 C++ 编写的开源 IDE，非常适合 C、C++ 和 Fortran 开发。它是跨平台的，可以在 Linux、macOS 和 Windows 上运行。


Code Blocks 是轻量级和快速的。它支持工作区、多目标项目、工作区内的项目间依赖关系。


你可以得到语法高亮、代码折叠、标签式界面、类浏览器、智能缩进等功能。你还可以通过插件扩展 IDE 的功能。


在本教程中，你将学习如何在基于 Ubuntu 的 Linux 发行版上安装 Code Blocks。



> 
> 注意
> 
> 
> Code Blocks 也可以在 Ubuntu 软件中心找到。然而，从 Ubuntu 21.04 开始，从 Ubuntu 软件中心以图形方式安装 Code Blocks 会安装一个 codeblocks-common 软件包，而不是图形化 IDE。因而你不能看到安装在你系统上的 Code Blocks 以运行。由于这个原因，我建议采取终端的方式在 Ubuntu 上安装 Code Blocks。
> 
> 
> 


### 在基于 Ubuntu 的 Linux 发行版上安装 Code Blocks


[Code Blocks IDE](https://www.codeblocks.org/) 在所有 Ubuntu 版本的 universe 库中都有。虽然它通常是默认启用的，但先[启用 universe 仓库](https://itsfoss.com/ubuntu-repositories/)也无妨：



```
sudo add-apt-repository universe

```

更新软件包缓存，这样系统就能知道新添加的仓库中的额外软件包的可用性：



```
sudo apt update

```

最后，你可以使用 `apt install` 命令在基于 Ubuntu 的发行版上安装 Code Blocks：



```
sudo apt install codeblocks

```

![](/data/attachment/album/202106/14/164815l2l5n7firblqnroq.png)


建议你也安装额外的插件，以便从 Code Blocks IDE 中获得更多。你可以使用 `codeblocks-contrib` 包来安装它们：



```
sudo apt install codeblocks-contrib

```

### 如何使用 Code Blocks


在系统菜单中搜索 “Code Blocks”。这是在 Ubuntu 默认的 GNOME 版本中的样子：


![](/data/attachment/album/202106/14/164817y5i0ucz5syuynccn.jpg)


当你第一次启动 Code Blocks 时，它会寻找你系统中所有可用的编译器，并将其添加到路径中，这样你就不用自己去配置它了。


在我的例子中，我的 Ubuntu 系统上已经安装了 gcc，Code Blocks 很好地识别了它。


![](/data/attachment/album/202106/14/164819d0k2zmmamdhuh6uw.png)


Code Blocks 的用户界面绝对不够现代，但请记住，这个 IDE 是轻量级的，它几乎消耗不到 50MB 的内存。


如果你曾经使用过像 Eclipse 这样的其他 IDE，你就不会觉得使用 Code Block 有什么困难。你可以写你的代码并把它们组织在项目中。


构建、运行并构建和运行按钮一起放在顶部。


![](/data/attachment/album/202106/14/164821pwrwzgolrl2zjxcg.png)


当你运行代码时，它会打开一个新的终端窗口来显示输出。


![](/data/attachment/album/202106/14/164822lmwd2e2ehheqt3ux.png)


这就是你需要的关于 Code Blocks 的最少信息。剩下的留给你，你可以通过浏览它的 [维基](https://wiki.codeblocks.org/index.php/Main_Page) 和[用户手册](https://www.codeblocks.org/user-manual/) 来进一步探索它。


拥有一个 IDE 可以使 [在 Linux 上运行 C 或 C++ 程序](https://itsfoss.com/c-plus-plus-ubuntu/) 更容易。Eclipse 是一个很好的 IDE，但它比 Code Blocks 要消耗更多的系统资源。当然，最后，重要的是你的选择。




---


via: <https://itsfoss.com/install-code-blocks-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
Code Blocks is an open source IDE written in C++ and ideal for C, C++ and Fortran development. It is cross-platform and runs on Linux, macOS and Windows.

Code Blocks is lightweight and fast. It supports workspaces, multi-target projects, inter project dependencies inside workspace.

You get syntax highlighting, code folding, tabbed interface, class browser, smart indentation and more. You can also extend the feature of the IDE via plugins.

In this tutorial, you’ll learn to install Code Blocks on Ubuntu-based Linux distributions.

Note

Code Blocks is also available in Ubuntu Software Center. However, as of Ubuntu 21.04, installing Code Blocks graphically from the Ubuntu Software Center installs a codeblocks-common package, not the graphical IDE. And thus you don’t see the Code Blocks installed on your system to run. For this reason, I recommend taking the terminal approach for installing Code Blocks on Ubuntu.

## Install Code Blocks on Ubuntu-based Linux distributions

The [Code Blocks IDE](https://www.codeblocks.org/) is available in the universe repository of all Ubuntu releases. Though it is usually enabled by default, it won’t harm to [enable universe repository](https://itsfoss.com/ubuntu-repositories/) first:

`sudo add-apt-repository universe`


Update the package cache so that system knows about the availability of the additional packages from the newly added repository:

`sudo apt update`


And finally, you can install Code Blocks on Ubuntu-based distributions using the apt install command:

`sudo apt install codeblocks`


![install code blocks ubuntu](https://itsfoss.com/content/images/wordpress/2021/05/install-code-blocks-ubuntu-800x445.png)

It is advised to also install additional plugins to get more out of the Code Blocks IDE. You can install them using the codeblocks-contrib package:

`sudo apt install codeblocks-contrib`


## How to use Code Blocks

Search for Code Blocks in the system menu. This is what it looks like in Ubuntu’s default GNOME version:

![code blocks ubuntu](https://itsfoss.com/content/images/wordpress/2021/06/code-blocks-ubuntu-800x231.jpg)

When you first start Code Blocks, it looks for all the available compilers on your system and adds it to the path so you don’t have to configure it on your own.

In my case, I already had gcc installed on my Ubuntu system and it was well recognized by Code Blocks.

![code blocks ide first run](https://itsfoss.com/content/images/wordpress/2021/05/code-blocks-ide-first-run-800x529.png)

The user interface of Code Blocks is definitely not modern but keep in mind that the IDE is lightweight and it hardly consumes 50 MB of RAM.

If you have ever used another IDE like Eclipse, you won’t find it difficult to use Code Block. You can write your code and organize them in projects.

The buttons to build, run and build and run together is right their on the top.

![code blocks ide](https://itsfoss.com/content/images/wordpress/2021/06/code-blocks-ide-800x543.png)

When you run the code, it opens a new terminal window to display the output.

![code blocks code run terminal](https://itsfoss.com/content/images/wordpress/2021/06/code-blocks-code-run-terminal.png)

That’s the bare minimum information you need about Code Blocks. I leave it up to you to explore it further by going through its [wiki](https://wiki.codeblocks.org/index.php/Main_Page) and [user manual](https://www.codeblocks.org/user-manual/).

Having an IDE makes [running C or C++ programs on Linux](https://itsfoss.com/c-plus-plus-ubuntu/) easier. Eclipse is a good IDE for that job but it consumes more system resources than Code Blocks. Of course, in the end, it’s your choice that matters.