quickstart-standard-env-setup.md 15.5 KB
Newer Older
E
ester.zhou 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# Setting Up Environments for Standard System


## System Requirements

- Windows: Windows 10 (64-bit)

- Ubuntu: Ubuntu 18.04 or later; recommended memory: 16 GB or higher.

- User name: cannot contain Chinese characters

- DevEco Device Tool: 3.0 Release


## Installing Necessary Libraries and Tools

To install the necessary libraries and tools, perform the following steps.

In Ubuntu:

1. Run the following **apt-get** command:
E
ester.zhou 已提交
22
   
E
ester.zhou 已提交
23 24 25 26
   ```
   sudo apt-get update && sudo apt-get install binutils binutils-dev git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib gcc-arm-linux-gnueabi libc6-dev-i386 libc6-dev-amd64 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip ruby genext2fs device-tree-compiler make libffi-dev e2fsprogs pkg-config perl openssl libssl-dev libelf-dev libdwarf-dev u-boot-tools mtd-utils cpio doxygen liblz4-tool openjdk-8-jre gcc g++ texinfo dosfstools mtools default-jre default-jdk libncurses5 apt-utils wget scons python3.8-distutils tar rsync git-core libxml2-dev lib32z-dev grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5-dev libncursesw5 libstdc++6 gcc-arm-none-eabi vim ssh locales
   ```

E
ester.zhou 已提交
27
   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
28 29 30 31 32 33 34
   > The preceding command is applicable to Ubuntu 18.04. For other Ubuntu versions, modify the preceding installation command based on the installation package name. Specifically:
   > 
   > - Python 3.8 or a later version is required. This section uses Python 3.8 as an example.
   > 
   > - Java 8 or later is required. This section uses Java 8 as an example.

2. Set Python 3.8 as the default Python version.
E
ester.zhou 已提交
35 36
   Check the location of Python 3.8:

E
ester.zhou 已提交
37
   
E
ester.zhou 已提交
38 39
   ```
   which python3.8
E
ester.zhou 已提交
40 41
   ```

E
ester.zhou 已提交
42
     Change python and python3 to python3.8.
E
ester.zhou 已提交
43
   
E
ester.zhou 已提交
44 45 46 47 48 49 50 51 52 53
   ```
   sudo update-alternatives --install /usr/bin/python python {python3.8 path} 1    #{Python3.8 path} is the location of Python 3.8 obtained in the previous step.
   sudo update-alternatives --install /usr/bin/python3 python3 {python3.8 path} 1   #{Python3.8 path} is the location of Python 3.8 obtained in the previous step.
   ```


## Installing DevEco Device Tool

To remotely access the Ubuntu environment through Windows to perform operations such as burning, you need to install DevEco Device Tool on both Windows and Ubuntu.

E
ester.zhou 已提交
54
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
55 56 57 58 59 60 61 62 63 64
> DevEco Device Tool is a one-stop integrated development environment (IDE) provided for developers of OpenHarmony-powered smart devices. It allows code editing, compiling, burning, and debugging. This document describes how to use DevEco Device Tool to remotely connect to the Ubuntu environment for burning and running.


### Installing DevEco Device Tool for Windows

1. Download the [DevEco Device Tool 3.0 Release](https://device.harmonyos.com/cn/ide#download) Windows edition.

2. Decompress the DevEco Device Tool package, double-click the installer, and then click **Next**.

3. Set the installation path of DevEco Device Tool and click **Next**. You are advised to install DevEco Device Tool in a non-system drive.
E
ester.zhou 已提交
65
   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78
   > If you have installed DevEco Device Tool 3.0 Beta2 or earlier, the earlier version will be uninstalled before you install a new version. If the following error message is displayed during the uninstallation, click **Ignore** to continue the installation. This error does not affect the installation of the new version.
   > 
   > ![en-us_image_0000001239275843](figures/en-us_image_0000001239275843.png)

   ![en-us_image_0000001270076961](figures/en-us_image_0000001270076961.png)

4. When prompted, select the tools to be automatically installed.
   1. On the **VSCode installation confirm** page, select **Install VScode 1.62.2 automatically** and click **Next**.
       > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
       > If Visual Studio Code 1.62 or later has been installed, this step will be skipped.

       ![en-us_image_0000001237801283](figures/en-us_image_0000001237801283.png)
   2. On the displayed **Python select page**, select **Download from Huawei mirror** and click **Next**.
E
ester.zhou 已提交
79
       > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
80 81 82 83 84 85 86 87
       > If Python 3.8 or 3.9 has been installed, select **Use one of compatible on your PC**.

       ![en-us_image_0000001193983334](figures/en-us_image_0000001193983334.png)

5. In the dialog box shown below, click **Next** to download and install the tools..

   ![en-us_image_0000001239634067](figures/en-us_image_0000001239634067.png)

E
ester.zhou 已提交
88 89 90 91 92
6. Read the user agreement and privacy statement carefully, select I accept the licenses, and click **Next**.

   ![en-us_image_0000001307019009](figures/en-us_image_0000001307019009.png)

7. Wait for the DevEco Device Tool setup wizard to automatically install DevEco Device Tool. After the installation is complete, click **Finish** to close the setup wizard.
E
ester.zhou 已提交
93 94 95

   ![en-us_image_0000001239650137](figures/en-us_image_0000001239650137.png)

E
ester.zhou 已提交
96
8. From Visual Studio Code, access the DevEco Device Tool page. Now you can conduct your development in DevEco Device Tool.
E
ester.zhou 已提交
97 98 99 100 101 102 103 104

   ![en-us_image_0000001225760456](figures/en-us_image_0000001225760456.png)


### Installing DevEco Device Tool for Ubuntu

1. Make sure the Ubuntu shell environment is **bash**.
   1. Run the following command and check whether the command output is **bash**. If the command output is not **bash**, go to step 2.
E
ester.zhou 已提交
105
      
E
ester.zhou 已提交
106 107 108 109 110 111
       ```
       ls -l /bin/sh
       ```

       ![en-us_image_0000001226764302](figures/en-us_image_0000001226764302.png)
   2. Start the command-line tool, run the following command, enter your password, and select **No** to set **Ubuntu shell** to **bash**.
E
ester.zhou 已提交
112
      
E
ester.zhou 已提交
113 114 115 116 117 118 119 120 121
       ```
       sudo dpkg-reconfigure dash
       ```

       ![en-us_image_0000001243641075](figures/en-us_image_0000001243641075.png)

2. Download the [DevEco Device Tool 3.0 Release Linux version](https://device.harmonyos.com/cn/ide#download).

3. Decompress the DevEco Device Tool software package and assign permission on the folder obtained from the decompression.
E
ester.zhou 已提交
122
   1. Go to the directory where the DevEco Device Tool software package is stored and run the following command to decompress the software package. In the command, change **devicetool-linux-tool-3.0.0.401.zip** to the actual software package name.
E
ester.zhou 已提交
123
      
E
ester.zhou 已提交
124
       ```
E
ester.zhou 已提交
125
       unzip devicetool-linux-tool-3.0.0.401.zip
E
ester.zhou 已提交
126
       ```
E
ester.zhou 已提交
127
   2. Open the folder of the decompressed software package and run the following command to grant the execute permission on the installation file. In the command, change **devicetool-linux-tool-3.0.0.401.sh** to the actual installation file name.
E
ester.zhou 已提交
128
      
E
ester.zhou 已提交
129
       ```
E
ester.zhou 已提交
130
       chmod u+x devicetool-linux-tool-3.0.0.401.sh
E
ester.zhou 已提交
131 132
       ```

E
ester.zhou 已提交
133
4. Run the following command to install DevEco Device Tool, where **devicetool-linux-tool-3.0.0.401.sh** indicates the installation file name.
E
ester.zhou 已提交
134
   
E
ester.zhou 已提交
135
   ```
E
ester.zhou 已提交
136
   sudo ./devicetool-linux-tool-3.0.0.401.sh
E
ester.zhou 已提交
137
   ```
E
ester.zhou 已提交
138 139 140 141 142 143
   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
   > During the installation, the setup wizard automatically checks whether Python 3.8 or 3.9 is installed. If Python 3.8 or 3.9 is not installed, the setup wizard displays the "Do you want to continue?" message; enter **Y** to allow the setup wizard to automatically install Python.
   > 
   > During the installation, the page for agreeing to the user agreement and privacy statement is displayed. Read and agree to the user agreement and privacy statement.
   > 
   > If this page is not displayed and the installation exits, run the apt-get install whiptail command, then the installation command.
E
ester.zhou 已提交
144 145 146 147 148 149

   Wait until the "Deveco Device Tool successfully installed." message is displayed.

   ![en-us_image_0000001198722374](figures/en-us_image_0000001198722374.png)


E
ester.zhou 已提交
150
## Configuring Windows to Remotely Access the Ubuntu Development Environment
E
ester.zhou 已提交
151 152 153 154 155


### Installing the SSH Service and Obtaining the IP Address for Remote Access

1. In Ubuntu, open the Terminal tool and run the following command to install the SSH service:
E
ester.zhou 已提交
156
   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
157 158
   > If the command fails to be executed and the system displays a message indicating that the openssh-server and openssh-client depend on different versions, install the openssh-client of the required version (for example, **sudo apt-get install openssh-client=1:8.2p1-4**) as prompted on the command-line interface (CLI) and run the command again to install the openssh-server.

E
ester.zhou 已提交
159
   
E
ester.zhou 已提交
160 161 162 163 164
   ```
   sudo apt-get install openssh-server
   ```

2. Run the following command to start the SSH service:
E
ester.zhou 已提交
165
   
E
ester.zhou 已提交
166 167 168 169 170
   ```
   sudo systemctl start ssh
   ```

3. Run the following command to obtain the IP address of the current user for remote access to the Ubuntu environment from Windows:
E
ester.zhou 已提交
171
   
E
ester.zhou 已提交
172 173 174 175 176 177 178 179 180
   ```
   ifconfig
   ```

   ![en-us_image_0000001215737140](figures/en-us_image_0000001215737140.png)


### Installing Remote SSH

E
ester.zhou 已提交
181
1. Open Visual Studio Code in Windows, click ![en-us_image_0000001239080359](figures/en-us_image_0000001239080359.png), and search for **remote-ssh** in the Extension Marketplace.
E
ester.zhou 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195

   ![en-us_image_0000001193920448](figures/en-us_image_0000001193920448.png)

2. Click **Install** to install Remote-SSH. After the installation is successful, **Remote-SSH** is displayed on the **INSTALLED** list.

   ![en-us_image_0000001238880335](figures/en-us_image_0000001238880335.png)


### Remotely Connecting to the Ubuntu Environment

1. Open Visual Studio Code in Windows, click ![en-us_image_0000001238760373](figures/en-us_image_0000001238760373.png), and click + on the **REMOTE EXOPLORER** page.

   ![en-us_image_0000001215878922](figures/en-us_image_0000001215878922.png)

E
ester.zhou 已提交
196
2. In the **Enter SSH Connection Command** text box, enter **ssh *ssh _username_\@_ip_address_***, where *ip_address* indicates the IP address of the remote computer to be connected and *username* indicates the account name used for logging in to the remote computer.
E
ester.zhou 已提交
197 198 199 200 201 202 203 204 205 206 207 208

   ![en-us_image_0000001215879750](figures/en-us_image_0000001215879750.png)

3. In the displayed dialog box, select the default first option as the SSH configuration file.

   ![en-us_image_0000001260519729](figures/en-us_image_0000001260519729.png)

4. Under **SSH TARGETS**, find the remote computer and click ![en-us_image_0000001194080414](figures/en-us_image_0000001194080414.png) to start it.

   ![en-us_image_0000001215720398](figures/en-us_image_0000001215720398.png)

5. In the displayed dialog box, select **Linux**, select **Continue**, and enter the password for logging in to the remote computer.
E
ester.zhou 已提交
209 210 211
   > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
   > To eliminate the need for frequently entering the password for logging in to the remote computer, set an SSH public key.
   
E
ester.zhou 已提交
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
   ![en-us_image_0000001215897530](figures/en-us_image_0000001215897530.png)

   After the connection is successful, the plug-in is automatically installed in the .vscode-server folder on the remote computer. After the installation is complete, reload Visual Studio Code in Windows as prompted. Then you can develop, compile, and burn source code in DevEco Device Tool on Windows.


## Obtaining Source Code

In the Ubuntu environment, perform the following steps to obtain the OpenHarmony source code:


### Preparations

1. Register your account with Gitee.

2. Register an SSH public key for access to Gitee.

3. Install the git client and git-lfs. (Skip this step if these tools have been installed in Installing Required Libraries and Tools. )

E
ester.zhou 已提交
230
   Update the software source:
E
ester.zhou 已提交
231 232 233 234 235
     
   ```
   sudo apt-get update
   ```

E
ester.zhou 已提交
236
   Run the following command to install the tools:
E
ester.zhou 已提交
237
   
E
ester.zhou 已提交
238 239 240 241 242
   ```
   sudo apt-get install git git-lfs
   ```

4. Configure user information.
E
ester.zhou 已提交
243
   
E
ester.zhou 已提交
244 245 246 247 248 249 250
   ```
   git config --global user.name "yourname"
   git config --global user.email "your-email-address"
   git config --global credential.helper store
   ```

5. Run the following commands to install the **repo** tool:
E
ester.zhou 已提交
251
   
E
ester.zhou 已提交
252 253
   In this example, **~/bin** is used as an example installation directory. You can change the directory as needed.
   
E
ester.zhou 已提交
254
   ```
E
ester.zhou 已提交
255 256 257
   mkdir ~/bin
   curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o ~/bin/repo 
   chmod a+x ~/bin/repo
E
ester.zhou 已提交
258 259
   pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
   ```
E
ester.zhou 已提交
260
6. Add the path of the **repo** tool to environment variables.
E
ester.zhou 已提交
261

E
ester.zhou 已提交
262 263 264 265 266
   ```
   vim ~/.bashrc               # Edit environment variables.
   export PATH=~/bin:$PATH     # Add the path of the **repo** tool to the end of environment variables.
   source ~/.bashrc            # Apply environment variables.
   ```
E
ester.zhou 已提交
267

E
ester.zhou 已提交
268
### Procedure
E
ester.zhou 已提交
269

E
ester.zhou 已提交
270
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
271 272 273 274
> Download the master code if you want to get quick access to the latest features for your development. Download the release code, which is more stable, if you want to develop commercial functionalities.

- **Obtaining OpenHarmony master code**

E
ester.zhou 已提交
275
  Method 1 \(recommended\): Use the **repo** tool to download the source code over SSH. \(You must have registered an SSH public key for access to Gitee.\)
E
ester.zhou 已提交
276 277 278 279 280 281 282 283 284
    
  ```
  repo init -u git@gitee.com:openharmony/manifest.git -b master --no-repo-verify
  repo sync -c
  repo forall -c 'git lfs pull'
  ```

  Method 2: Use the **repo** tool to download the source code over HTTPS.

E
ester.zhou 已提交
285
  
E
ester.zhou 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298
  ```
  repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
  repo sync -c
  repo forall -c 'git lfs pull'
  ```

- **Obtaining OpenHarmony release code**

  For details about how to obtain the source code of an OpenHarmony release, see the [Release-Notes](../../release-notes/Readme.md).


### Running prebuilts

E
ester.zhou 已提交
299
Go to the root directory of the source code and run the following script to install the compiler and binary tool:
E
ester.zhou 已提交
300

E
ester.zhou 已提交
301 302 303 304 305 306 307 308 309 310
```
bash build/prebuilts_download.sh
```


## Installing the Compilation Tool

hb is a compilation tool of OpenHarmony. To install hb in Ubuntu, perform the following steps: For details about the functions of the OpenHarmony compilation and building module, see [Compilation and Building Guidelines](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-build.md).


E
ester.zhou 已提交
311
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br>
E
ester.zhou 已提交
312
> To install a proxy, see [Configuring the Proxy](../quick-start/quickstart-standard-reference.md#section6204129143012).
E
ester.zhou 已提交
313 314 315


1. Run the following command to install hb and update it to the latest version:
E
ester.zhou 已提交
316
   
E
ester.zhou 已提交
317 318 319 320 321
   ```
   pip3 install --user build/lite
   ```

2. Set the environment variable.
E
ester.zhou 已提交
322
   
E
ester.zhou 已提交
323 324 325 326
   ```
   vim ~/.bashrc
   ```

E
ester.zhou 已提交
327
   Copy the following command to the last line of the .bashrc file, save the file, and exit.
E
ester.zhou 已提交
328
   
E
ester.zhou 已提交
329 330 331 332
   ```
   export PATH=~/.local/bin:$PATH
   ```

E
ester.zhou 已提交
333
   Update the environment variable.
E
ester.zhou 已提交
334
   
E
ester.zhou 已提交
335 336 337 338 339
   ```
   source ~/.bashrc
   ```

3. Run the **hb -h** command in the source code directory. If the following information is displayed, the installation is successful:
E
ester.zhou 已提交
340
   
E
ester.zhou 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
   ```
   usage: hb
   
   OHOS build system
   
   positional arguments:
     {build,set,env,clean}
       build               Build source code
       set                 OHOS build settings
       env                 Show OHOS build env
       clean               Clean output
   
   optional arguments:
     -h, --help            show this help message and exit
   ```


E
ester.zhou 已提交
358
> ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE**<br>
E
ester.zhou 已提交
359
> - Run the following command to uninstall hb:
E
ester.zhou 已提交
360
>    
E
ester.zhou 已提交
361 362 363 364 365
>   ```
>   pip3 uninstall ohos-build
>   ```
> 
> - If any issue occurs during the hb installation, see [FAQs](../quick-start/quickstart-standard-faq-hb.md) to troubleshoot.