# 安装开发工具

## 设置环境变量

方便起见，可以先在终端里设置一个叫做**RISCV**的环境变量(在bash命令里可以通&#x8FC7;**$RISCV**使用)，作为你安装所有和riscv有关的软件的路径。在`/etc/profile`里面写一行`export RISCV=/your/path/to/riscv`之类的东西就行。后面安装的各个项目最好也放在上面的的路径里面。当然需要去创建这个文件夹。

最小的软件开发环境需要：能够编译程序，能够运行程序。开发操作系统这样的系统软件也不例外。

## 安装VScode

进入其官网进行下载安装即可，与Windows类似。

## 安装git

```
sudo aptitude install git
```

git下载完后记得初始化噢\~并且与自己的github连接起来。

## 安装编译器

我们使用的计算机都是基于x86架构的。如何把程序编译到riscv64架构的汇编？这需要我们使用“目标语言为riscv64机器码的编译器”，在我们的电脑上进行**交叉编译**。

放心，这里不需要你自己写编译器。我们使用现有的riscv-gcc编译器即可。从<https://github.com/riscv/riscv-gcc> clone下来，然后在x86架构上编译riscv-gcc编译器为可执行的x86程序，就可以运行它，来把你的程序源代码编译成riscv架构的可执行文件了。这有点像绕口令，但只要有一点编译原理的基础就可以理解。不过，这个riscv-gcc仓库很大，而且自己编译工具链总是一件麻烦的事。

其实，没必要那么麻烦，我们大可以使用别人已经编译好的编译器的可执行文件，也就是所谓的**预编译（prebuilt）**&#x5DE5;具链，下载下来，放在你喜欢的地方（比如之前定义&#x7684;**$RISCV**），配好路径（把编译器的位置加到系统的**PATH**环境变量里），就能在终端使用了。我们推荐使用sifive公司提供的预编译工具链，[下载](https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2020.04.0-x86_64-linux-ubuntu14.tar.gz?_ga=2.228907996.1572454202.1596898073-1498217945.1596898073)“GNU Embedded Toolchain ”。然后解压到之前的riscv文件夹下，把里面的bin文件夹加入到环境变量。修改完记得运行`source /etc/profile`噢。

配置好后，在终端输入`riscv64-unknown-elf-gcc -v`查看安装的gcc版本, 如果输出一大堆东西且最后一行有`gcc version 某个数字.某个数字.某个数字`，说明gcc配置成功，否则需要检查一下哪里做错了，比如环境变量**PATH**配置是否正确。一般需要把一个形如`..../bin`的目录加到**PATH**里。

{% hint style="info" %}
可能有人会说，到底该怎么去做嘛，烦人，都没有写完。没有写完的，剩一点点的需要自己去查资料，自己实现哦\~
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nankai.gitbook.io/ucore-os-on-risc-v64/lab0/pei-zhi-huan-jing/an-zhuang-kai-fa-gong-ju.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
