Ubuntu24.04 初始配置

一、换源

  1. 备份源配置文件
1
sudo cp /etc/apt/sources.list.d/ubuntu.sources  /etc/apt/sources.list.d/ubuntu.sources.bak
  1. 复制清华镜像源

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

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
29
30
31
32
33
34
35
36
37
38
39
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble noble-updates noble-backports
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# Types: deb-src
# URIs: http://security.ubuntu.com/ubuntu/
# Suites: noble-security
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# 预发布软件源,不建议启用

# Types: deb
# URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# Suites: noble-proposed
# Components: main restricted universe multiverse
# Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

# # Types: deb-src
# # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
# # Suites: noble-proposed
# # Components: main restricted universe multiverse
# # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
  1. 编辑源配置文件
1
sudo vim /etc/apt/sources.list.d/ubuntu.sources
  1. 更新
1
2
sudo apt update
sudo apt upgrade

二、配置C++环境

  1. 安装编译工具及必要组件
1
sudo apt install build-essential gdb git
  1. 检查安装
1
2
3
4
gcc --version
g++ --version
gdb --version
git --version

三、配置vscode

  1. 安装必要组件
1
sudo apt install openssh-server
  1. 检查SSH服务状态
1
sudo systemctl status ssh
  1. 查看防火墙状态
1
sudo ufw status
  1. 关闭防火墙
1
2
sudo systemctl stop ufw.service
sudo systemctl disable ufw.service
  1. 创建目录
1
mkdir -p ~/.vscode-server/bin
  1. 下载vscode-server

根据vscodecommit id下载vscode-server-linux-x64.tar.gz

https://update.code.visualstudio.com/commit:commit_id/server-linux-x64/stable

例:https://update.code.visualstudio.com/commit:c306e94f98122556ca081f527b466015e1bc37b0/server-linux-x64/stable

vscode-server-linux-x64.tar.gz传入 ~/.vscode-server/bin

  1. 配置vscode-server

c306e94f98122556ca081f527b466015e1bc37b0为自己的commit id

1
2
3
4
5
6
cd ~/.vscode-server/bin
tar -zxvf vscode-server-linux-x64.tar.gz
mv vscode-server-linux-x64 c306e94f98122556ca081f527b466015e1bc37b0
rm vscode-server-linux-x64.tar.gz
cd ~/.vscode-server/bin/c306e94f98122556ca081f527b466015e1bc37b0
touch 0
  1. 配置 SSH免密登录

windows 操作

根据输出结果 找到id_ed25519.pub, 复制内容

1
ssh-keygen -C "your email address"

ubuntu 操作

若没有authorized_keys文件,则先通过 touch~/.ssh/authorized_keys创建

1
vim ~/.ssh/authorized_keys
  1. 通过vscode连接ubuntu

四、参考资料

  1. https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
  2. https://zhuanlan.zhihu.com/p/493050003