Ubuntu24.04 系统深度实战:虚拟机安装|Netplan 网络|Apt 包管理全解析
2026/9/11 23:06:27 网站建设 项目流程

ubuntu 2404 系统安装

创建虚拟机

创建过程省略。

安装过程

提示:为了防止连网更新软件包,该地方需断开网卡安装系统。系统安装完成后,再配置网络。

更改地址为 http://mirrors.aliyun.com/ubuntu

使用华为的mirror速度更快:http://mirrors.huaweicloud.com/ubuntu

等待安装完成,该过程需要从Internet上下载软件包,还可以查看安装日志。

安装完成

重启系统

出现以下提示,不用理会,直接回车继续重启。

[FAIED] Failed unmounting /dev/cdrom

安装后配置

安装常规软件包

vim和命令补全软件包。

ggg@ubuntu:~$sudoapt-getinstall-yvimbash-completion

配置 IP

ggg@ubuntu:~$cd/etc/netplan/ ggg@ubuntu:/etc/netplan$sudomkdirbackup ggg@ubuntu:/etc/netplan$sudomv50-cloud-init.yaml backup ggg@ubuntu:/etc/netplan$sudovim00-installer-config.yaml# This is the network config written by 'subiquity'network: ethernets: ens32: dhcp4: no addresses: -10.1.8.10/24 routes: - to: default via:10.1.8.2 nameservers: addresses: -223.5.5.5 -223.6.6.6 version:2# 应用配置ggg@ubuntu:/etc/netplan$sudochmod60000-installer-config.yaml ggg@ubuntu:/etc/netplan$sudonetplan apply

配置 root 密码

ggg@ubuntu:~$sudopasswdroot[sudo]passwordforggg:`123`New password:`123`Retype new password:`123`passwd: password updated successfully

配置 root 远程登录

ggg@ubuntu:~$sudovim/etc/ssh/sshd_config#PermitRootLogin prohibit-passwordPermitRootLoginyes# 重新sshd服务配置ggg@ubuntu:~$sudosystemctl reloadsshggg@ubuntu:~$sudosystemctlenablessh

ubuntu 系统网络管理

netplan

介绍

Netplan是Canonical(Ubuntu系统的开发和维护组织)开发的实用程序,能在Linux系统上轻松配置网络。要配置网络接口,只需创建所需网络接口的YAML描述,然后Netplan将为所选的渲染器工具生成所有必需的配置。

您可以在/usr/share/doc/netplan/examples中找到Netplan网络配置文件。Netplan当前支持以下后端渲染器,例如NetworkManagerSystemd-networkd

netplan只是NetworkManagerSystemd-networkd前端工具。

Netplan定义文件位于/etc/netplan目录,例如/etc/netplan/00-ens32.yaml

示例

示例1:定义一个静态配置ip

root@ubuntu:/usr/share/doc/netplan/examples# cat static.yaml
network:ethernets:ens33:dhcp4:noaddresses:-10.1.8.88/24routes:-to:defaultvia:10.1.8.2nameservers:addresses:-10.1.8.2-223.5.5.5version:2

示例2:定义一个动态获取ip

root@ubuntu:/usr/share/doc/netplan/examples# cat dhcp.yaml
network:version:2renderer:networkdethernets:enp3s0:dhcp4:true

命令

应用上面定义的配置文件:

root@ubuntu:~# netplan apply# 获取当前配置信息root@ubuntu:~# netplan getnetwork: version:2ethernets: ens33: addresses: -"10.1.8.88/24"nameservers: addresses: -10.1.8.2 -223.5.5.5 dhcp4:falseroutes: - to:"default"via:"10.1.8.2"

ubuntu 系统软件包管理

使用apt管理软件包

atp和apt-xxx命令 区别-中文

atp和apt-xxx命令 区别-英文

apt 和 其他apt命令

命令区别

虽然 apt 与 apt-get 有一些类似的命令选项,但它并不能完全向下兼容 apt-get 命令。也就是说,可以用 apt 替换部分 apt-get 系列命令,但不是全部。

apt 命令取代的命令命令的功能
apt installapt-get install安装软件包
apt removeapt-get remove移除软件包
apt purgeapt-get purge移除软件包及配置文件
apt updateapt-get update刷新存储库索引
apt upgradeapt-get upgrade升级所有可升级的软件包
apt autoremoveapt-get autoremove自动删除不需要的包
apt full-upgradeapt-get dist-upgrade在升级软件包时自动处理依赖关系
apt searchapt-cache search搜索应用程序
apt showapt-cache show显示装细节

apt 还有一些自己的命令:

新的apt命令命令的功能
apt list列出包含条件的包(已安装,可升级等)
apt edit-sources编辑源列表

apt

子命令
root@ubuntu:~# apt --<tab><tab>autoclean dependsinstallreinstall update autopurge dist-upgrade list remove upgrade autoremove download moo search build-dep edit-sources policy show changelog full-upgrade purge showsrc cleanhelprdependssource
update 子命令

update - update list of available packages

从软件仓库中获取最新软件清单。

root@ubuntu:~# apt update

相当于yum makecache

list 子命令

list - list packages based on package names

查看软件仓库中软件清单。

# 可用于查看的选项root@ubuntu:~# apt list --<tab><tab>--all-versions --manual-installed--upgradable--installed--target-release--verbose# 查看软件包清单root@ubuntu:~# apt listWARNING:aptdoes not have a stable CLI interface. Use with cautioninscripts. Listing... 0ad-data-common/jammy,jammy0.0.25b-1 all 0ad-data/jammy,jammy0.0.25b-1 all 0ad/jammy0.0.25b-2 amd64 0install-core/jammy2.16-2 amd64......# 查看特定软件包root@ubuntu:~# apt list openssh-serverListing... Done openssh-server/jammy-updates,now1:8.9p1-3ubuntu0.1 amd64[installed]openssh-server/jammy-updates1:8.9p1-3ubuntu0.1 i386# 查看特定软件包所有版本root@ubuntu:~# apt list openssh-server --all-versionsListing... Done openssh-server/jammy-updates,now1:8.9p1-3ubuntu0.1 amd64[installed]openssh-server/jammy1:8.9p1-3 amd64 openssh-server/jammy-updates1:8.9p1-3ubuntu0.1 i386 openssh-server/jammy1:8.9p1-3 i386
show 子命令

show - show package details

查看仓库中软件包详细信息。

root@ubuntu:~# apt show openssh-server# 类似 dpkg -s openssh-server
search 子命令

search - search in package descriptions

root@ubuntu:~# apt search --<tab><tab>--full--names-only root@ubuntu:~# apt search --names-only apache2
install 子命令

install - install packages

从仓库中获取软件包并安装。

root@ubuntu:~# apt install --<tab><tab>--allow-change-held-packages --fix-broken--purge--allow-downgrades --fix-missing--reinstall--allow-insecure-repositories --fix-policy--remove--allow-remove-essential --force-yes --show-progress --allow-unauthenticated --ignore-hold --show-upgraded --arch-only --ignore-missing--simulate--assume-no --install-recommends--solver--assume-yes --install-suggests --target-release --auto-remove --no-install-recommends --trivial-only--download--no-install-suggests--upgrade--download-only --only-upgrade --verbose-versions --dry-run --print-uris root@ubuntu:~# apt install apache2 -y# 安装特定版本root@ubuntu:~# apt install apache2=2.4.52-1ubuntu4.5
reinstall 子命令

reinstall - reinstall packages

从仓库中获取软件包并再次安装(系统中已安装)。

root@ubuntu:~# apt reinstall apache2 -y
remove 子命令

remove - remove packages

卸载系统中已安装软件包。

root@ubuntu:~# apt remove apache2 -yReading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap Use'apt autoremove'to remove them. The following packages will be REMOVED: apache20upgraded,0newly installed,1to remove and282not upgraded. After this operation,546kB disk space will be freed.(Reading database...202598files and directories currently installed.)Removing apache2(2.4.52-1ubuntu4.5)... Processing triggersforman-db(2.10.2-1)... Processing triggersforufw(0.36.1-4build1)...
autoremove 子命令

autoremove - Remove automatically all unused packages

root@ubuntu:~# apt autoremove -y
upgrade 子命令

upgrade - upgrade the system by installing/upgrading packages

# 升级系统所有可更新软件包root@ubuntu:~# apt upgrade# 升级系统中特定软件包root@ubuntu:~# apt upgrade openssh-server -y
full-upgrade 子命令

full-upgrade - upgrade the system by removing/installing/upgrading packages

# 升级系统所有可更新软件包root@ubuntu:~# apt full-upgrade# 升级系统中特定软件包root@ubuntu:~# apt full-upgrade openssh-server -y
download 子命令

download - download packages

root@ubuntu:~# apt download openssh-serverroot@ubuntu:~# lsopenssh-server_1%3a8.9p1-3ubuntu0.1_amd64.deb
edit-sources 子命令

edit-sources - edit the source information file

root@ubuntu:~# export EDITOR=vimroot@ubuntu:~# apt edit-sources# 使用vim编辑文件 /etc/apt/sources.list

apt-file

作用:查找软件包中文件。

apt-file is a command line tool for searching files in packages for the APT package management system.

帮助信息
root@ubuntu:~# apt-file --helpapt-file[options]action[pattern]apt-file[options]-faction<file>apt-file[options]-Daction<debfile>Pattern options:================--fixed-string-FDo notexpandpattern --from-deb-DUsefilelist of .deb package(s)as patterns;implies-F--from-file-fRead patterns from file(s), one per line(use'-'forstdin)--ignore-case-iIgnorecasedistinctions--regexp-xpattern is a regular expression --substring-match pattern is a substring(no glob/regex)Search filter options:======================--architecture-a<arch>Use specific architecture[L]--index-names-I<names>Only search indices listedin<names>[L]--filter-suites<suites>Only search indicesforthe listed<suites>[L](E.g."unstable")--filter-origins<origins>Only search indices from<origins>[L](E.g."Debian")Other options:==============--config-c<file>Parse the given APT configfile[R]--option-o<A::B>=<V>Set the APT config option A::B to"V"[R]--package-only-lOnly display packages name--verbose-vruninverbose mode[R]--help-hShow this help. -- End of options(necessaryifpattern starts with a'-')[L]: Takes a comma-separated list of values.[R]: The option can be used repeatedly Action: list|show<pattern>List filesinpackages list-indices List indices configuredinAPT. search|find<pattern>Search filesinpackages update Fetch Contents files from apt-sources.
示例
# 更新apt仓库中文件清单缓存root@ubuntu:~# apt-file update# 仓库中某个软件包的文件清单root@ubuntu:~# apt-file list openssh-serveropenssh-server: /etc/default/ssh openssh-server: /etc/init.d/ssh openssh-server: /etc/pam.d/sshd openssh-server: /etc/ssh/moduli openssh-server: /etc/ufw/applications.d/openssh-server openssh-server: /lib/systemd/system/rescue-ssh.target......# 使用正则表达式查询ifconfig工具由哪个软件包提供root@ubuntu:~# apt-file -x search '.*bin/ifconfig$'net-tools: /sbin/ifconfig

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询