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 Mac.
Having said that, the list of things I plan to buy is as follows. (hardwares only)
- Arch Linux
- MacBook Pro
- PS 5
Do I really need so many computers, and can I really afford the price?
It’s useless to talk, let’s start.
The sorting of these packages has no context,(expect
sudo) write wherever I think.
apt-get install sudo
sudo executes commands as the system administrator, that is, the commands run via
sudo seem to be run by root.
sudo apt update sudo apt install git
sudo apt updateis 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.
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.
git config --global user.name "Your Name" git config --global user.email "email@example.com"
sudo apt update sudo apt upgrade
sudo apt update sudo apt install curl
To verify that curl is installed, type
curl in a terminal.
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.
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
tar -xf Python-3.9.15.tar.xz cd Python-3.9.15/ ./configure --enable-optimizations
nproc to get the number of cores, you need modify the number after
make -j 2 to make it equal with your cores.
Here we assume 2 cores, run
make -j 2 sudo make altinstall python3.11 --version
There we replace
sudo make installwith
sudo make altinstall, because
make installwill rewriting the system default python version.
1.4.4 Install Python packages
sudo apt install python3-[package-name]
Here we install
pip3 as example, all of the commands of pip are
sudo apt-get 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
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.
Docker official provides a one-click script, which saves our tedious work.
curl -fsSL https://get.docker.com | bash -s docker
If you are live in mainland China, you can use the
mirrorto increase the download speed, by using the
--mirrorparameter, for instance, using Aliyun.
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
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
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.
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
curl -L https://github.com/docker/compose/releases/download/v2.14.2/docker-compose-linux-`uname -m` > ./docker-compose
unname -mmeans 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.
chmod +x ./docker-compose mv ./docker-compose /usr/local/bin/docker-compose
List Docker containers
docker ps -aq
Stop all containers
docker stop $(docker ps -aq)
Delete all containers
docker rm $(docker ps -aq)
Delete all images
docker rmi $(docker images -q)
Delete specified image
docker rmi <mage-id>
For Linux, you need to get used to using the command code to get things done, which is different from Window and Mac, 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.