1# Setting Up Ubuntu Development Environment<a name="EN-US_TOPIC_0000001174350605"></a> 2 3- [Obtaining Source Code and Tools](#section1897711811517) 4- [Obtaining Source Code](#section1545225464016) 5- [Installing Necessary Libraries and Tools](#section108201740181219) 6- [Installing Python3](#section1238412211211) 7- [Installing LLVM \(Required only for OpenHarmony\_v1.x\)](#section12202192215415) 8- [Installing hb](#section15794154618411) 9 - [Prerequisites](#section1083283711515) 10 - [Installation Procedure](#section11518484814) 11 - [Uninstalling hb](#section3512551574) 12 13 14Operating system: 64-bit version of Ubuntu 16.04 or later. 15 16Perform the following steps to set up the development environment: 17 181. Obtain source code. 192. Install necessary libraries and tools. 203. Install Python3. 214. Install LLVM \(required only for OpenHarmony\_v1.x\). 225. Install hb. 23 24> **NOTICE:** 25>- Docker is provided for the Ubuntu build environment, which encapsulates related build tools. If you use Docker to prepare the build environment, you do not need to perform the following steps in this section. For details, see [Using Docker to Prepare the Build Environment](../get-code/gettools-acquire.md#section107932281315). 26>- By default, basic software, such as Samba and Vim, is installed in the system. Adaptation on the software is required to support file sharing between the Linux server and the Windows workstation. 27>- For details about the compilation and building subsystem of OpenHarmony, see [Compilation and Building Overview](../subsystems/subsys-build-mini-lite.md). 28 29## Obtaining Source Code and Tools<a name="section1897711811517"></a> 30 31The following table describes the tools and source code required for setting up the general environment for a Linux server and how to obtain these tools and the source code. 32 33**Table 1** Source code and development tools and their obtaining methods 34 35<a name="table6299192712513"></a> 36<table><thead align="left"><tr id="row122993276512"><th class="cellrowborder" valign="top" width="25.779999999999998%" id="mcps1.2.4.1.1"><p id="p1829914271858"><a name="p1829914271858"></a><a name="p1829914271858"></a>Item</p> 37</th> 38<th class="cellrowborder" valign="top" width="30.819999999999997%" id="mcps1.2.4.1.2"><p id="p429918274517"><a name="p429918274517"></a><a name="p429918274517"></a>Description</p> 39</th> 40<th class="cellrowborder" valign="top" width="43.4%" id="mcps1.2.4.1.3"><p id="p12997271757"><a name="p12997271757"></a><a name="p12997271757"></a>How to Obtain</p> 41</th> 42</tr> 43</thead> 44<tbody><tr id="row45863354112"><td class="cellrowborder" valign="top" width="25.779999999999998%" headers="mcps1.2.4.1.1 "><p id="p3587173513117"><a name="p3587173513117"></a><a name="p3587173513117"></a>Source code</p> 45</td> 46<td class="cellrowborder" valign="top" width="30.819999999999997%" headers="mcps1.2.4.1.2 "><p id="p258713581118"><a name="p258713581118"></a><a name="p258713581118"></a>Develops functions.</p> 47</td> 48<td class="cellrowborder" valign="top" width="43.4%" headers="mcps1.2.4.1.3 "><p id="p16587835171114"><a name="p16587835171114"></a><a name="p16587835171114"></a>See <a href="../get-code/sourcecode-acquire.md">Source Code Acquisition</a>.</p> 49</td> 50</tr> 51<tr id="row020505735919"><td class="cellrowborder" valign="top" width="25.779999999999998%" headers="mcps1.2.4.1.1 "><p id="p1220513576596"><a name="p1220513576596"></a><a name="p1220513576596"></a>Necessary libraries and tools</p> 52</td> 53<td class="cellrowborder" valign="top" width="30.819999999999997%" headers="mcps1.2.4.1.2 "><p id="p2206157145919"><a name="p2206157145919"></a><a name="p2206157145919"></a>Used for compilation (such as packaging and image creation).</p> 54</td> 55<td class="cellrowborder" valign="top" width="43.4%" headers="mcps1.2.4.1.3 "><p id="p920675719597"><a name="p920675719597"></a><a name="p920675719597"></a>Internet</p> 56</td> 57</tr> 58<tr id="row430016273514"><td class="cellrowborder" valign="top" width="25.779999999999998%" headers="mcps1.2.4.1.1 "><p id="p330015271158"><a name="p330015271158"></a><a name="p330015271158"></a>Python3.7+</p> 59</td> 60<td class="cellrowborder" valign="top" width="30.819999999999997%" headers="mcps1.2.4.1.2 "><p id="p43003270510"><a name="p43003270510"></a><a name="p43003270510"></a>Executes script compilation.</p> 61</td> 62<td class="cellrowborder" valign="top" width="43.4%" headers="mcps1.2.4.1.3 "><p id="p34760459518"><a name="p34760459518"></a><a name="p34760459518"></a>Internet</p> 63</td> 64</tr> 65<tr id="row7531362055"><td class="cellrowborder" valign="top" width="25.779999999999998%" headers="mcps1.2.4.1.1 "><p id="p1467122152710"><a name="p1467122152710"></a><a name="p1467122152710"></a>LLVM (required only for OpenHarmony_v1.x)</p> 66</td> 67<td class="cellrowborder" valign="top" width="30.819999999999997%" headers="mcps1.2.4.1.2 "><p id="p1739432372718"><a name="p1739432372718"></a><a name="p1739432372718"></a>Functions as the compiler toolchain.</p> 68</td> 69<td class="cellrowborder" valign="top" width="43.4%" headers="mcps1.2.4.1.3 "><p id="p59711534202610"><a name="p59711534202610"></a><a name="p59711534202610"></a>Internet</p> 70</td> 71</tr> 72<tr id="row1644079184919"><td class="cellrowborder" valign="top" width="25.779999999999998%" headers="mcps1.2.4.1.1 "><p id="p744115914493"><a name="p744115914493"></a><a name="p744115914493"></a>hb</p> 73</td> 74<td class="cellrowborder" valign="top" width="30.819999999999997%" headers="mcps1.2.4.1.2 "><p id="p1244114913492"><a name="p1244114913492"></a><a name="p1244114913492"></a>Compiles the <span id="text344823833918"><a name="text344823833918"></a><a name="text344823833918"></a>OpenHarmony</span> source code.</p> 75</td> 76<td class="cellrowborder" valign="top" width="43.4%" headers="mcps1.2.4.1.3 "><p id="p1463918124619"><a name="p1463918124619"></a><a name="p1463918124619"></a>Internet</p> 77</td> 78</tr> 79</tbody> 80</table> 81 82> **NOTICE:** 83>- If you acquire the source code using an HPM component or HPM CLI tool, you do not need to install compilation tools like **gn** and **ninja**. 84>- \(Recommended\) If you obtain the source code via the mirror site or code repository, install compilation tools such as **gn**, **ninja**, and LLVM. When installing these tools, ensure that their environment variable paths are unique. 85 86## Obtaining Source Code<a name="section1545225464016"></a> 87 88You need to acquire [source code](../get-code/sourcecode-acquire.md), download it on a Linux server, and decompress it. 89 90## Installing Necessary Libraries and Tools<a name="section108201740181219"></a> 91 92Run the following command to install the libraries and tools required for compilation: 93 94``` 95sudo apt-get install build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi 96``` 97 98## Installing Python3<a name="section1238412211211"></a> 99 1001. Start a Linux server. 1012. Run the following command to check the Python version: 102 103 ``` 104 python3 --version 105 ``` 106 107 If Python version is earlier than 3.7, reinstall Python. Do as follows to install Python, for example, Python 3.8. 108 109 1. Check the Ubuntu version. 110 111 ``` 112 cat /etc/issue 113 ``` 114 115 1. Install Python based on the Ubuntu version. 116 - If the Ubuntu version is 18 or later, run the following command: 117 118 ``` 119 sudo apt-get install python3.8 120 ``` 121 122 - If the Ubuntu version is 16, perform the following steps: 123 124 a. Install dependency packages. 125 126 ``` 127 sudo apt update && sudo apt install software-properties-common 128 ``` 129 130 b. Add the source of deadsnakes PPA and press **Enter**. 131 132 ``` 133 sudo add-apt-repository ppa:deadsnakes/ppa 134 ``` 135 136 c. Install Python 3.8. 137 138 ``` 139 sudo apt upgrade && sudo apt install python3.8 140 ``` 141 142 1433. Set the soft link of **python** and **python3** to **python3.8**. 144 145 ``` 146 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 147 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 148 ``` 149 1504. Install and upgrade the Python package management tool \(pip3\) using either of the following methods: 151 - **Command line:** 152 153 ``` 154 sudo apt-get install python3-setuptools python3-pip -y 155 sudo pip3 install --upgrade pip 156 ``` 157 158 - **Installation package:** 159 160 ``` 161 curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 162 python get-pip.py 163 ``` 164 165 166 167## Installing LLVM \(Required only for OpenHarmony\_v1.x\)<a name="section12202192215415"></a> 168 169> **NOTICE:** 170>When downloading source code under the OpenHarmony\_v1.x branches or tags, perform the operation procedure described in this section to install LLVM 9.0.0. 171>When downloading source code under the Master and OpenHarmony\_v2.x branches or tags, skip this section. The hb automatically downloads the latest version of LLVM. 172 1731. Start a Linux server. 1742. [Download LLVM](https://repo.huaweicloud.com/harmonyos/compiler/clang/9.0.0-36191/linux/llvm-linux-9.0.0-36191.tar). 1753. Decompress the LLVM installation package to **\~/llvm**. 176 177 ``` 178 tar -zxvf llvm.tar.gz -C ~/ 179 ``` 180 1814. Set an environment variable. 182 183 ``` 184 vim ~/.bashrc 185 ``` 186 187 Copy the following command to the last line of the **.bashrc** file, save the file, and exit. 188 189 ``` 190 export PATH=~/llvm/bin:$PATH 191 ``` 192 1935. Validate the environment variable. 194 195 ``` 196 source ~/.bashrc 197 ``` 198 199 200## Installing hb<a name="section15794154618411"></a> 201 202### Prerequisites<a name="section1083283711515"></a> 203 204Python 3.7.4 or later has been installed. For details, see [Installing Python3](#section1238412211211). 205 206### Installation Procedure<a name="section11518484814"></a> 207 2081. Install **hb**. 209 210 ``` 211 python3 -m pip install --user ohos-build 212 ``` 213 2142. Set an environment variable. 215 216 ``` 217 vim ~/.bashrc 218 ``` 219 220 Copy the following command to the last line of the **.bashrc** file, save the file, and exit. 221 222 ``` 223 export PATH=~/.local/bin:$PATH 224 ``` 225 226 Update the environment variable. 227 228 ``` 229 source ~/.bashrc 230 ``` 231 2323. Run the **hb -h** command. If the following information is displayed, the installation is successful: 233 234 ``` 235 usage: hb 236 237 OHOS build system 238 239 positional arguments: 240 {build,set,env,clean} 241 build Build source code 242 set OHOS build settings 243 env Show OHOS build env 244 clean Clean output 245 246 optional arguments: 247 -h, --help Show this help message and exit 248 ``` 249 250 251### Uninstalling hb<a name="section3512551574"></a> 252 253``` 254python3 -m pip uninstall ohos-build 255``` 256 257> **NOTICE:** 258>If you encounter any problem during the installation, resort to the [FAQs](quickstart-lite-env-setup-faqs.md). 259 260