The purpose of changing the source in CentOS is to accelerate package downloads, by modifying the pointing of baseurl in the source file configuration file (/etc/yum.repos.d/). The specific steps are as follows: Back up the original configuration file: sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak Edit the configuration file (taking CentOS-Base.repo as an example): sudo vim /etc/yum.repos.d/CentOS-Base.repo find the baseurl line and change it to domestic
CentOS source change: Stop being tortured again!
Many friends have complained that CentOS's source is as slow as a snail. It has not been moved for a long time after downloading a package, which is simply crazy. This article will talk about how to change sources gracefully and completely get rid of the trouble of download speed. After reading it, you can not only easily change the source, but also understand the tricks, and you will never have to worry about this mess again!
First of all, you have to know that CentOS uses yum, and this package management tool relies on source files to obtain software packages. Source files are like the address of a huge software supermarket, and the default source usually points to a foreign server, so slow! What we need to do is to change this address to a domestic mirror site.
Basics: Don't be afraid, it's actually very simple
You only need to know the /etc/yum.repos.d/
directory, which stores all yum source configuration files. These files are usually ended with .repo
. Don't worry, you don't need to understand any complicated Linux commands, simple text editing is enough.
Core: Change the source, which means changing the configuration file!
Open your /etc/yum.repos.d/
directory and you will see a bunch of .repo
files, each corresponding to a source. For example, CentOS-Base.repo
, this is the configuration file of the CentOS main source. These files are what we want to modify.
I personally prefer to use Alibaba Cloud's source because it is stable and fast. Of course, you can also choose Tsinghua University, University of Science and Technology of China, etc., search for it yourself, and there are many choices.
Practice: Take Alibaba Cloud as an example and teach you step by step
Back up the original file first. This is a good habit. If you correct it wrong, you can still recover it:
<code class="bash">sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak</code>
Then, open CentOS-Base.repo
with your favorite text editor (vim, nano):
<code class="bash">sudo vim /etc/yum.repos.d/CentOS-Base.repo</code>
Find the baseurl
line and change it to Alibaba Cloud's source address, for example:
<code>baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/</code>
Don’t forget to change other baseurl
to the corresponding addresses of Alibaba Cloud, such as epel
source. The complete configuration file may be relatively long. Check it carefully to make sure that all baseurl
point to Alibaba Cloud. Save the file and exit the editor.
Test: A moment to witness miracles!
Finally, update the yum cache and see the effect:
<code class="bash">sudo yum makecache</code>
Then try to install a software package, such as sudo yum install vim
, to see if the download speed is much faster!
Advanced Usage: Play with multiple sources
You can also use multiple sources at the same time to improve reliability. Add multiple baseurl
to the configuration file, yum will automatically try to download from different sources, and if one source fails, it will try others. It's like finding a few more stores when buying things and you can always find the right one.
Guide to trapping in pits: Avoid unnecessary trouble
- Backup! Backup! Backup! Say important things three times! Be sure to back up before modifying the configuration file to avoid misoperation.
- Check it carefully! When modifying the configuration file, be sure to carefully check each parameter to ensure it is correct. A small error may cause yum to not work properly.
- Choose the right source! Different source speeds and stability are different, so choosing a reliable source is very important. It is recommended to try a few more sources to find the one that suits you best.
- Version matching! Make sure that the source you choose is compatible with your CentOS version. Version mismatch may cause installation failure.
Remember, changing the source is just a small trick, and more importantly, understanding the working principle of yum and the structure of the configuration file. With these masters, you can easily deal with various Linux system management problems! I wish you a successful source change and a flying feeling from now on!
The above is the detailed content of How to change the source of centos. For more information, please follow other related articles on the PHP Chinese website!

Alternatives to CentOS include RockyLinux, AlmaLinux, OracleLinux, and SLES. 1) RockyLinux and AlmaLinux provide RHEL-compatible binary packages and long-term support. 2) OracleLinux provides enterprise-level support and Ksplice technology. 3) SLES provides long-term support and stability, but commercial licensing may increase costs.

Alternatives to CentOS include UbuntuServer, Debian, Fedora, RockyLinux, and AlmaLinux. 1) UbuntuServer is suitable for basic operations, such as updating software packages and configuring the network. 2) Debian is suitable for advanced usage, such as using LXC to manage containers. 3) RockyLinux can optimize performance by adjusting kernel parameters.

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

CentOS installation steps: Download the ISO image and burn bootable media; boot and select the installation source; select the language and keyboard layout; configure the network; partition the hard disk; set the system clock; create the root user; select the software package; start the installation; restart and boot from the hard disk after the installation is completed.

The command to restart the SSH service is: systemctl restart sshd. Detailed steps: 1. Access the terminal and connect to the server; 2. Enter the command: systemctl restart sshd; 3. Verify the service status: systemctl status sshd.

Restarting the network in CentOS 8 requires the following steps: Stop the network service (NetworkManager) and reload the network module (r8169), start the network service (NetworkManager) and check the network status (by ping 8.8.8.8)


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.