Installing Tools

In GNU/Linux, you can download and install a software by one command (which may be difficult to do in Windows). This is achieved by the package manager. Different GNU/Linux distribution has different package manager. In Ubuntu, the package manager is called apt.

You will download and install some tools needed for the PAs from the network mirrors. Before using the network mirrors, you should check whether the system can access the Internet.

Checking network state

Inside NJU, you should easily obtain an IPv6 address. To test this, try to ping a mirror host with IPv6 support:

ping mirrors.tuna.tsinghua.edu.cn -c 4

You should receive reply packets successfully:

PING mirrors.tuna.tsinghua.edu.cn(2402:f000:1:408:8100::1 (2402:f000:1:408:8100::1)) 56 bytes of data.
64 bytes from 2402:f000:1:408:8100::1 (2402:f000:1:408:8100::1): icmp_seq=1 ttl=54 time=1.56 ms
64 bytes from 2402:f000:1:408:8100::1 (2402:f000:1:408:8100::1): icmp_seq=2 ttl=54 time=1.07 ms
64 bytes from 2402:f000:1:408:8100::1 (2402:f000:1:408:8100::1): icmp_seq=3 ttl=54 time=1.07 ms
64 bytes from 2402:f000:1:408:8100::1 (2402:f000:1:408:8100::1): icmp_seq=4 ttl=54 time=1.24 ms

--- mirrors.tuna.tsinghua.edu.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 7ms
rtt min/avg/max/mdev = 1.071/1.237/1.563/0.203 ms

If you do not have an IPv6 address, you may access the Internet by IPv4 address. You can try to ping a host outside the university LAN:

ping www.baidu.com -c 4

If you can ping Baidu successfully, you should successfully ping the mirror host above, too.

Setting APT source file

如果你的系统不是Ubuntu 22.04, 请更换合适的源

使用与系统不相符的源会导致工具包版本冲突, 强行安装将会损坏系统. 如果你使用的系统不是Ubuntu 22.04, 请勿使用以下的源, 你可以在这里在新窗口中打开选择相应的Ubuntu版本, 并将源更换成选择的结果.

Run the following commands to update the APT source file:

sed -i "s/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g" /etc/apt/sources.list

However, you will receive an error message:

sed: /etc/apt/sources.list: Permission denied

This is because the APT source file is owned by root, and you do not have the permission to modify it.

One solution is first switching to the root account. But to avoid switching, an alternative way is to use sudo. If you find an operation requires superuser permission, append sudo before that operation. Before using sudo, you should add your account to the sudo group. But first, you still need to switch to the root account.

su -
Password:

Enter the root password you set during the installation. Note that the password is not shown in the terminal to avoid password leaks. If the password is correct, you will see the prompt changes:

root@hostname:/home/username#

The last character is #, instead of $ before you executing su -. # is the indicator of root account. Now you can add your account to the sudo group.

adduser username sudo  # Change `username` to your user name
exit

To let the changes to take effect, you should log out or reboot. After that, try

whoami
sudo whoami

If it is the first time you run sudo, enter the password of your account. You should find that sudo whoami will output root.

Now you can use sudo to modify the APT source file. This time you should modify it successfully. To check this, you can output the file:

cat /etc/apt/sources.list

You should see it really outputs the line you just updated.

Updating APT package information

Now you can tell apt to retrieve software information from the sources:

apt-get update

However, you will receive an error message:

E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/

This is because apt-get requires superuser privilege to run. Run the command with superuser privilege. Since it requires Internet accessing, it may cost some time to finish.

遇到could not resolve 'cn.mirrors.tuna.tsinghua.edu.cn'的错误

这可能是因为你在安装Ubuntu时默认源选择了国内镜像, 导致默认的sources.list被修改造成的. 为了修复这个问题, 你需要额外运行以下命令:

sed -i "s/cn.mirrors.tuna/mirrors.tuna/g" /etc/apt/sources.list

然后尝试重新运行apt-get update.

Installing tools for PAs

The following tools are necessary for PAs:

apt-get install build-essential    # build-essential packages, include binary utilities, gcc, make, and so on
apt-get install man                # on-line reference manual
apt-get install gcc-doc            # on-line reference manual for gcc
apt-get install gdb                # GNU debugger
apt-get install git                # revision control system
apt-get install libreadline-dev    # a library used later
apt-get install libsdl2-dev        # a library used later

The usage of these tools is explained later.

Installing Chinese input method

Search the Internet for how to install a Chinese input method in Ubuntu.