Icey One
My wish is to see you again, even across the world.
Linux Note

Preface

This article is used to record my often used Linux (Debian/Ubuntu) commands.

Suppose we get a server which system version is Debian 11 and only apt installed, because my Hosting Server provides such machines, (because this can save storage?) so we have to install packages we need.

So far, I haven’t used a Linux computer, it’s said that Arch is a good OS for personal computer. If possible, I hope to buy one after work, and experience the difference between Windows and Linux, my plan is to buy it after get the MacBook.

Having said that, the list of things I plan to buy is as follows. (hardwares only)

  1. Phone
    1. iPhone
    2. Pixel
  2. Computer
    1. Arch Linux
    2. MacBook Pro
  3. PlayStation 5
  4. NAS
  5. Router

Do I really need so many computers, and can I really afford the price?

It’s useless to talk, let’s start.

1. Packages

The sorting of these packages has no context,(expect sudo) write wherever I think.

1.1. Sudo

1
apt-get install sudo

The sudo executes commands as the system administrator, that is, the commands run via sudo seem to be run by root.

1.2. Git

1.2.1 Install

1
2
sudo apt update
sudo apt install git

sudo apt update is a very common command, we will use it in almost all commands. If you have experience, you may encounter a command that keeps reporting errors, but you can do it when run sudo apt update.

We can verify that the installation was successful using git --version, it will print the following if the installation is successful.

1
2
3
git --version

git version 2.25.1

As of now, the latest version of git is 2.25.1.

1.2.2 Configure Git

This section is not for novices, because in normal, we don’t need to link GitHub.

Now, we have successfully installed Git, if need to login in GitHub, run the following code.

1
2
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"

1.2.3 Update

1
2
sudo apt update
sudo apt upgrade

1.3. Curl

1
2
sudo apt update
sudo apt install curl

To verify that curl is installed, type curl in a terminal.

1.4. Python

1.4.1 Install

Here we take Python 3.11 as an example, you can replace it with any version you want to install.

You can find all version in here , and replace the link of you want download.

1
2
3
4
5
6
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev \
libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev \
libreadline-dev libffi-dev curl libbz2-dev curl -y

curl -O https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tar.xz

1.4.2 Unzip and configure

1
2
3
tar -xf Python-3.11.1.tar.xz
cd Python-3.9.15
./configure --enable-optimizations

1.4.3 Compile

run nproc to get the number of cores, you need modify the number after -j of make -j 2 to make it equal with your cores.

Here we assume 2 cores, run

1
2
3
make -j 2 
sudo make altinstall
python3.11 --version

There we replace sudo make install with sudo make altinstall, because make install will rewriting the system default python version.

1.4.4 Install Python packages

1
sudo apt install python3-[package-name]

1.5 Pip

Here we install pip3 as example, all of the commands of pip are python, and pip3 is python3

1
sudo apt install python-pip

In general, pip corresponds to Python 2.7, and pip3 corresponds to Python 3.x.

If you want update pip version, run python -m pip3 install -U pip

2. Docker

Docker is a very handy tool, i really like it It helps me do many things, for example, my Telegram bot (private) is made by Docker, if you can use Docker well, then you are a good coder.

Of course I am a junior for Docker, only some basic commands.

2.1 Install

2.1.1 Docker

Docker official provides a one-click script, which saves our tedious work.

1
curl -fsSL https://get.docker.com | bash -s docker

If you are live in mainland China, you can use the mirror to increase the download speed, by using the --mirror parameter, for instance, using Aliyun.

1
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

If the user logging in to Linux isn’t root, the docker needs to join the docker group. Run this code

1
2
sudo groupadd docker # docker group
sudo usermod -aG docker $USER #add current docker to docker group

Log in to the ssh terminal again, and run docker version to test whether docker is installed. If it’s correct, it will print the following

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Client: Docker Engine - Community
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:28:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:25:58 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

If you are using docker for the first time, I recommend running docker run hello-world, this will help you get started with Docker.

2.1.2 Compose

Docker Compose is a more popular tool than Docker. One you have a Compose file, you can create and start your application with a single command: docker compose up.

Let’s start the installing Compose

1
curl -L https://github.com/docker/compose/releases/download/v2.14.2/docker-compose-linux-`uname -m` > ./docker-compose
  • unname -m means general version, automatically install the appropriate version for your machine.
  • Pay attention to replace 2.14.2 with the required version, you can go to Docker Compose releases to find more.

Don’t forget to grant permissions after the download is complete, and move to the correct path.

1
2
chmod +x ./docker-compose
mv ./docker-compose /usr/local/bin/docker-compose

2.2 Commands

List Docker containers

1
docker ps -aq

Stop all containers

1
docker stop $(docker ps -aq)

Delete all containers

1
docker rm $(docker ps -aq)

Delete all images

1
docker rmi $(docker images -q)

Delete specified image

1
docker rmi <mage-id>

Summary

For Linux, you need to get used to using the command code to get things done, which is different from Window and MacBook, and you need better trouble-shooting and resolution skills. If you find a problem, I recommend reading the documentation.

Of course, we all use Linux, I believe we all have the sikll.