查看系统版本
lsb_release -a
修改软件源
-
Ubuntu 默认的软件源是境外的,速度上会有些问题,我们可以在「Software & Updates」(软件和更新)中选择国内的镜像。
-
还可以直接修改配置文件 https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.775b1b11o2W9u7
更新系统软件
sudo apt update
sudo apt upgrade
sudo apt autoremove
# Ubuntu 18.04
sudo apt install -y openssh-server build-essential gcc g++ clang git cmake make git-core gnupg flex bison zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig lzop samba samba-common vim libssl-dev libelf-dev python3-pip dh-autoreconf libexpat1-dev gettext libz-dev libghc-zlib-dev rsync gawk wget diffstat chrpath socat libsdl1.2-dev texinfo libpixman-1-dev libbz2-dev ccache docbook-utils python-pysqlite2 help2man desktop-file-utils libssh2-1-dev uuid-dev libglu1-mesa-dev mercurial autoconf automake groff asciidoc byobu tmux linux-tools-common dos2unix indent bcc gperf qttools5-dev global net-tools abootimg jq iputils-ping locales cpio bc dosfstools mtools m4
# Ubuntu 20.04
sudo apt install -y openssh-server build-essential gcc g++ clang git cmake make git-core gnupg flex bison zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig lzop samba samba-common vim libssl-dev libelf-dev python3-pip dh-autoreconf libexpat1-dev gettext libz-dev libghc-zlib-dev rsync gawk wget diffstat chrpath socat libsdl1.2-dev texinfo libpixman-1-dev libbz2-dev ccache docbook-utils python-pysqlite2 help2man desktop-file-utils libssh2-1-dev uuid-dev libglu1-mesa-dev mercurial autoconf automake groff asciidoc byobu tmux linux-tools-common dos2unix indent bcc gperf qttools5-dev global net-tools abootimg jq iputils-ping locales cpio bc dosfstools mtools m4 python2
# Ubuntu 22.04
sudo apt install -y openssh-server build-essential gcc g++ clang git cmake make git gnupg flex bison zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 libncurses5 lib32ncurses-dev x11proto-core-dev libx11-dev lib32z1-dev libgl1-mesa-dev libxml2-utils xsltproc unzip fontconfig lzop samba samba-common vim libssl-dev libelf-dev python3-pip dh-autoreconf libexpat1-dev gettext libz-dev libghc-zlib-dev rsync gawk wget diffstat chrpath socat libsdl1.2-dev texinfo libpixman-1-dev libbz2-dev ccache docbook-utils help2man desktop-file-utils libssh2-1-dev uuid-dev libglu1-mesa-dev mercurial autoconf automake groff asciidoc byobu tmux linux-tools-common dos2unix indent bcc gperf qttools5-dev global net-tools abootimg jq iputils-ping locales cpio bc dosfstools mtools m4 python2
# Ubuntu 24.04
sudo apt install -y \
openssh-server \
build-essential \
gcc g++ clang \
git git-lfs \
cmake make ninja-build \
gnupg flex bison \
zip unzip \
curl wget rsync \
zlib1g-dev \
gcc-multilib g++-multilib libc6-dev-i386 \
libncurses-dev libncursesw5-dev \
lib32z1-dev \
libgl1-mesa-dev libglu1-mesa-dev \
libxml2-utils xsltproc \
fontconfig \
lzop \
samba samba-common \
vim neovim \
libssl-dev \
libelf-dev \
python3 python3-pip python3-venv python3-dev \
dh-autoreconf \
libexpat1-dev gettext \
libz-dev \
rsync gawk diffstat chrpath socat \
libsdl2-dev \
texinfo \
libpixman-1-dev \
libbz2-dev \
ccache \
docbook-utils help2man \
desktop-file-utils \
libssh2-1-dev \
uuid-dev \
mercurial \
autoconf automake \
groff asciidoc \
byobu tmux \
linux-tools-generic \
dos2unix indent \
gperf \
qttools5-dev qtbase5-dev \
global \
net-tools \
abootimg \
jq \
iputils-ping \
locales \
cpio bc \
dosfstools mtools \
m4 \
tree htop iotop iftop \
ripgrep fd-find \
silversearcher-ag \
clangd lldb lld \
bear \
gdb valgrind strace ltrace \
linux-tools-generic \
libasound2-dev \
pulseaudio \
pulseaudio-utils \
pipewire \
libpulse-dev \
tcpdump nmap \
iperf3 \
dnsutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm -v
nvm install --lts
nvm use --lts
nvm alias default lts/*
node -v
npm -v
curl -fsSL https://bun.sh/install | bash
source ~/.bashrc
bash基本配置
```shell
# vim ~/.bashrc
check_net() {
echo "== DNS 检测 =="
if getent hosts google.com >/dev/null 2>&1; then
echo "DNS: OK"
else
echo "DNS: FAIL"
return 1
fi
echo "== TCP/HTTPS 检测 =="
if curl -s --connect-timeout 3 https://www.google.com >/dev/null; then
echo "HTTPS: OK"
else
echo "HTTPS: FAIL"
return 2
fi
echo "== GitHub 访问检测 =="
if curl -s --connect-timeout 3 https://raw.githubusercontent.com >/dev/null; then
echo "GitHub: OK"
else
echo "GitHub: FAIL"
return 3
fi
echo "== 网络正常 =="
return 0
}
proxy_on() {
PROXY_ADDRE=192.168.6.111:8890
export http_proxy="http://$PROXY_ADDRE"
export https_proxy="http://$PROXY_ADDRE"
export HTTP_PROXY="http://$PROXY_ADDRE"
export HTTPS_PROXY="http://$PROXY_ADDRE"
echo "代理已开启: $PROXY_ADDRE"
}
proxy_off() {
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
echo "代理已关闭"
}
alias vi='vim'
force_color_prompt=yes
function git_branch {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo -e " on \033[01;36m$branch"
fi
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u \[\033[00m\]@ \[\033[01;32m\]\h\[\033[00m\] in \[\033[01;33m\]\w\[\033[01;00m\]$(git_branch)\n\[\033[31m\]\$\[\033[00m\] '
export PATH="/home/wtp/bin:$PATH"
```
vim基本配置
```shell
# vim ~/.vimrc
set nu "在左侧行号
set tabstop=4 "tab 长度设置为 4
set nobackup "覆盖文件时不备份
set cursorline "突出显示当前行
set ruler "在右下角显示光标位置的状态行
set autoindent "自动缩进
set list "显示tab 换行符
set listchars=tab:>-,trail:- "显示制表符和空格
```
ssh服务
- 安装
sudo apt update
sudo apt install openssh-server
ssh免密登录失败
-
win10产生密钥
-
Ubuntu 添加密钥到 authorized_keys
-
修改配置文件:/etc/ssh/sshd_config
StrictModes no PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys PasswordAuthentication yes -
登录
ssh -i ~/.ssh/id_rsa xxx@192.168.1.103
git
- 安装
sudo apt update
sudo apt install git
sudo apt install cmake
- 配置
静态IP
- VirtualBox安装完Ubuntu后,默认应该是开启一块网卡,连接方式根据宿主电脑的连接方式来(如果物理机是通过有线上网,那么需要使用NAT网络连接方式,如果是无线网络,那么需要使用桥接方式上网),该网卡负责虚拟机的上网。
-
查看网卡名字
ifconfig -
sudo vim /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager #network: # ethernets: # enp0s3: # dhcp4: no # addresses: [192.168.1.103/24] # gateway4: 192.168.0.1 # nameservers: # addresses: [114.114.114.114, 8.8.8.8] # version: 2 - sudo netplan apply
ubuntu中安装samba文件服务
-
安装
sudo apt update sudo apt install samba samba-common -y -
配置内容
sudo vim /etc/samba/smb.conf[wtp] comment = wtp browseable = yes path = /home/wtp create mask = 0755 directory mask = 0755 valid users = wtp force user = wtp force group = wtp public = yes available = yes writable = yes -
添加用户
sudo smbpasswd -a wtp -
重启服务
sudo /etc/init.d/smbd restart
关闭终端提示音
- 在终端输入: sudo vim /etc/inputrc
- 找到 # set bell-style none 这一行,去掉前面的注释符号和空格。
- 重启终端
docker
- 安装docker
#1. 安装
# 官方仓库
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# 国内仓库
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Ubuntu 22.04
sudo apt-key list
# 0EBFCD88 是 [ unknown] Docker Release (CE deb) <docker@docker.com> 的 Pub的最后8个字符
sudo apt-key export 0EBFCD88 | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/slack.gpg
# 安装
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
#2. 修改配置
sudo gedit /etc/docker/daemon.json 为:
{
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
,"insecure-registries": [ "192.168.56.101:6088"]
}
#3.重启docker
sudo service docker restart
#4.将账号权限加入docker组:
sudo groupadd docker #添加docker用户组
sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
newgrp docker #更新用户
修改swap分区大小
#1. 查看swap分区大小
free -h
#2. 关闭swap分区
sudo swapoff /swapfile
free -h
#3. 修改swap分区大小到8GB
sudo fallocate -l 12G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
#4. 开启swap分区
sudo swapon /swapfile
#5. 查看swap分区大小
free -h
#6. 删除swap分区
sudo rm /swapfile
修复磁盘错误(Read-only file system)
sudo fsck /dev/sda5 -y
sudo reboot