Skip to main content

Ubuntu新系统安装脚本

· 4 min read
Alan

每次安装Ubuntu系统都要做一些初始化工作, 现记录如下, 方便下次使用.

安装软件

sudo apt-get update &&
sudo apt-get install -y \
git \
build-essential gcc \
net-tools \
flameshot \
vim \
wget \
network-manager-l2tp-gnome network-manager-strongswan \
vlc \
vpnc network-manager-vpnc-gnome \
ibus-rime

# cd /etc/apt
# git init
# chown -R alan .git/


sudo apt-get install ffmpeg -y # 视频处理类库
sudo apt-get install scrot -y # 命令行截图工具
sudo apt-get install simplescreenrecorder -y # 录屏工具

# 安装专业录屏、直播工具
sudo add-apt-repository ppa:obsproject/obs-studio && \
sudo apt-get update && \
sudo apt-get install ffmpeg obs-studio -y

# config git
git config --global core.editor "vim"
git config --global credential.helper "cache --timeout 360000"

# install remmina
sudo apt-add-repository ppa:remmina-ppa-team/remmina-next && \
apt-get update && \
apt install remmina remmina-plugin-rdp remmina-plugin-secret remmina-plugin-spice && \
killall remmina

# install official docker
sudo apt-get update && \
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
sudo apt-get update && \
sudo apt-get install docker-ce docker-ce-cli containerd.io -y && \
docker --version

# install docker by aliyun mirror
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
apt-get -y update
apt-get -y install docker-ce

# 安装 Chrome/Chromium
snap install chromium
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && sudo dpkg -i ./google-chrome-stable_current_amd64.deb

# 开启 SSH
sudo apt-get install openssh-server -y && \
sudo systemctl start ssh &&
sudo ufw allow ssh

Dock 图标居中

原文 How to customize dock panel on Ubuntu 20.04 Focal Fossa Linux

sudo apt install dconf-editor -y

打开 dconf-Editor, 定位到 org > gnome > shell > extensions > dash-to-dock, 修改以下配置:

04

或者使用命令行修改配置:

gsettings set org.gnome.shell.extensions.dash-to-dock extend-height false # 我在 Ubuntu 20.04 上测试, 只修改这一个配置即可, 这个值默认是 true
gsettings set org.gnome.shell.extensions.dash-to-dock dock-position BOTTOM
gsettings set org.gnome.shell.extensions.dash-to-dock transparency-mode FIXED
gsettings set org.gnome.shell.extensions.dash-to-dock dash-max-icon-size 64
gsettings set org.gnome.shell.extensions.dash-to-dock unity-backlit-items true

~/.bashrc

~/.bashrc 自定义配置:

# 设置 PS1 包含git分支名称
GREEN='\[\033[0;32m\]'
YELLOW='\[\033[0;33m\]'
RED='\[\033[0;31m\]'
BLUE='\[\033[0;34m\]'
RESET='\[\033[0m\]'

function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="$GREEN\u@\h$RESET:$BLUE\W$RESET\$(parse_git_branch) $ "

# 设置终端的 title
function set_gnome_terminal_title() {
local dir_name=$(basename "$PWD")
echo -ne "\033]0;${dir_name}$(parse_git_branch)\007"
}
PROMPT_COMMAND='set_gnome_terminal_title;'

# 设置常用命令别名
alias ll="ls -alh"
alias lr="ls -alhR"
alias lt="ls -alh --sort=time"
alias sc="systemctl"

# 定义基础目录
export data="/data"
export projects="$data/projects"
export programs="$data/programs"
export software="$data/software"
export temporary="$data/temporary"
export PATH="$PATH:$programs/commands"

# Node.js 版本控制工具 fnm
eval "$(fnm env --use-on-cd)"

# cnpm 脚本
alias cnpm="npm --registry=https://registry.npmmirror.com \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npmmirror.com/mirrors/node \
--userconfig=$HOME/.cnpmrc"

# Java 配置
export JAVA_HOME="$programs/jdk"
export M2_HOME="$programs/apache-maven"
export MAVEN_HOME="$programs/apache-maven"
export PATH="$PATH:$JAVA_HOME/bin"
export PATH="$PATH:$M2_HOME/bin"
export PATH="$PATH:$programs/spring-2.2.6.RELEASE/bin" # spring boot cli

# .Net Core
export DOTNET_ROOT="$programs/dotnet-core"
export PATH="$PATH:$DOTNET_ROOT"
export PATH="$PATH:$HOME/.dotnet/tools" # .net core global tool script

# Flutter
export FLUTTER_HOME="$projects/flutter"
export PATH="$PATH:$FLUTTER_HOME/bin"
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

# 其他
export PATH="$PATH:$programs/gh_2.22.1_linux_amd64/bin" # github cli

# Android ref: https://developer.android.google.cn/studio/command-line/variables?hl=zh-cn#envar
# https://developer.android.com/tools/variables
export REPO_OS_OVERRIDE=linux
export GRADLE_USER_HOME="$programs/gradle"
export ANDROID_ROOT_DIR="$programs/android-home"
export ANDROID_HOME="$ANDROID_ROOT_DIR/sdk"
export ANDROID_USER_HOME="$ANDROID_ROOT_DIR/.android/"
export ANDROID_EMULATOR_HOME="$ANDROID_ROOT_DIR/.android/"
export PATH="$PATH:$ANDROID_HOME/emulator"
export PATH="$PATH:$ANDROID_HOME/platform-tools"
export PATH="$PATH:$ANDROID_HOME/tools"
export PATH="$PATH:$ANDROID_HOME/tools/bin"

export NO_PROXY=localhost,127.0.0.0

stty -ixon

alias python=python3