1、ubuntu更换下载源

apt-get国内镜像源添加

  1. 备份源文件:
  2. sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
  3. 操作文件:
  4. vim /etc/apt/sources.list
  5. 添加源地址:
  6. #阿里云
  7. deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
  8. deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
  9. deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
  10. deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
  11. deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
  12. deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
  13. deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
  14. deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
  15. deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
  16. deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
  17. #网易163
  18. deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
  19. deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
  20. deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
  21. deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
  22. deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
  23. deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse
  24. deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse
  25. deb-src http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse
  26. deb-src http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse
  27. deb-src http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse
  28. 保存退出并更新源和软件:
  29. esc + :wq!
  30. sudo apt-get update
  31. sudo apt-get upgrade

软件中心国内镜像源添加(其实添加之后apt也是使用该镜像源,所以两种选一种即可)

图片.png

  1. sudo apt-get update
  2. sudo apt-get upgrade

pip国内镜像源添加

  1. vi ~/.pip/pip.conf
  2. 添加
  3. [global]
  4. #阿里云
  5. index-url = https://mirrors.aliyun.com/pypi/simple
  6. trusted-host = mirrors.aliyun.com
  7. #豆瓣
  8. index-url = http://pypi.douban.com/simple
  9. trusted-host=pypi.douban.com
  10. #清华大学
  11. index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
  12. trusted-host=pypi.tuna.tsinghua.edu.cn
  13. #中国科技大学
  14. index-url = https://pypi.mirrors.ustc.edu.cn/simple/
  15. trusted-host=pypi.mirrors.ustc.edu.cn

2、ubuntu定制

  • 常用清理命令

图片.png

  • 配置shell
    查看ubuntu内置的shell:

    cat /etc/shells echo $SHELL


安装zsh:

sudo apt install zsh -y

设置zsh为系统默认shell:

chsh -s /bin/zsh (重启reboot)

安装oh-my-zsh更方便配置zsh:

vim oh-my-zsh.sh chmod +x install.sh apt-get -y install build-essential nghttp2 libnghttp2-dev libssl-dev ./oh-my-zsh.sh

  1. #!/bin/sh
  2. #
  3. # This script should be run via curl:
  4. # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  5. # or via wget:
  6. # sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  7. # or via fetch:
  8. # sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  9. #
  10. # As an alternative, you can first download the install script and run it afterwards:
  11. # wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
  12. # sh install.sh
  13. #
  14. # You can tweak the install behavior by setting variables when running the script. For
  15. # example, to change the path to the Oh My Zsh repository:
  16. # ZSH=~/.zsh sh install.sh
  17. #
  18. # Respects the following environment variables:
  19. # ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
  20. # REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
  21. # REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
  22. # BRANCH - branch to check out immediately after install (default: master)
  23. #
  24. # Other options:
  25. # CHSH - 'no' means the installer will not change the default shell (default: yes)
  26. # RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
  27. # KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
  28. #
  29. # You can also pass some arguments to the install script to set some these options:
  30. # --skip-chsh: has the same behavior as setting CHSH to 'no'
  31. # --unattended: sets both CHSH and RUNZSH to 'no'
  32. # --keep-zshrc: sets KEEP_ZSHRC to 'yes'
  33. # For example:
  34. # sh install.sh --unattended
  35. # or:
  36. # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
  37. #
  38. set -e
  39. # Track if $ZSH was provided
  40. custom_zsh=${ZSH:+yes}
  41. # Default settings
  42. ZSH=${ZSH:-~/.oh-my-zsh}
  43. REPO=${REPO:-ohmyzsh/ohmyzsh}
  44. REMOTE=${REMOTE:-https://github.com/${REPO}.git}
  45. BRANCH=${BRANCH:-master}
  46. # Other options
  47. CHSH=${CHSH:-yes}
  48. RUNZSH=${RUNZSH:-yes}
  49. KEEP_ZSHRC=${KEEP_ZSHRC:-no}
  50. command_exists() {
  51. command -v "$@" >/dev/null 2>&1
  52. }
  53. fmt_error() {
  54. printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2
  55. }
  56. fmt_underline() {
  57. printf '\033[4m%s\033[24m\n' "$*"
  58. }
  59. fmt_code() {
  60. # shellcheck disable=SC2016 # backtic in single-quote
  61. printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET"
  62. }
  63. setup_color() {
  64. # Only use colors if connected to a terminal
  65. if [ -t 1 ]; then
  66. RED=$(printf '\033[31m')
  67. GREEN=$(printf '\033[32m')
  68. YELLOW=$(printf '\033[33m')
  69. BLUE=$(printf '\033[34m')
  70. BOLD=$(printf '\033[1m')
  71. RESET=$(printf '\033[m')
  72. else
  73. RED=""
  74. GREEN=""
  75. YELLOW=""
  76. BLUE=""
  77. BOLD=""
  78. RESET=""
  79. fi
  80. }
  81. setup_ohmyzsh() {
  82. # Prevent the cloned repository from having insecure permissions. Failing to do
  83. # so causes compinit() calls to fail with "command not found: compdef" errors
  84. # for users with insecure umasks (e.g., "002", allowing group writability). Note
  85. # that this will be ignored under Cygwin by default, as Windows ACLs take
  86. # precedence over umasks except for filesystems mounted with option "noacl".
  87. umask g-w,o-w
  88. echo "${BLUE}Cloning Oh My Zsh...${RESET}"
  89. command_exists git || {
  90. fmt_error "git is not installed"
  91. exit 1
  92. }
  93. ostype=$(uname)
  94. if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -q msysgit; then
  95. fmt_error "Windows/MSYS Git is not supported on Cygwin"
  96. fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
  97. exit 1
  98. fi
  99. git clone -c core.eol=lf -c core.autocrlf=false \
  100. -c fsck.zeroPaddedFilemode=ignore \
  101. -c fetch.fsck.zeroPaddedFilemode=ignore \
  102. -c receive.fsck.zeroPaddedFilemode=ignore \
  103. --depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
  104. fmt_error "git clone of oh-my-zsh repo failed"
  105. exit 1
  106. }
  107. echo
  108. }
  109. setup_zshrc() {
  110. # Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
  111. # with datestamp of installation that moved them aside, so we never actually
  112. # destroy a user's original zshrc
  113. echo "${BLUE}Looking for an existing zsh config...${RESET}"
  114. # Must use this exact name so uninstall.sh can find it
  115. OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
  116. if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
  117. # Skip this if the user doesn't want to replace an existing .zshrc
  118. if [ "$KEEP_ZSHRC" = yes ]; then
  119. echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
  120. return
  121. fi
  122. if [ -e "$OLD_ZSHRC" ]; then
  123. OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
  124. if [ -e "$OLD_OLD_ZSHRC" ]; then
  125. fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
  126. fmt_error "re-run the installer again in a couple of seconds"
  127. exit 1
  128. fi
  129. mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
  130. echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
  131. "${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
  132. fi
  133. echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
  134. mv ~/.zshrc "$OLD_ZSHRC"
  135. fi
  136. echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
  137. sed "/^export ZSH=/ c\\
  138. export ZSH=\"$ZSH\"
  139. " "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
  140. mv -f ~/.zshrc-omztemp ~/.zshrc
  141. echo
  142. }
  143. setup_shell() {
  144. # Skip setup if the user wants or stdin is closed (not running interactively).
  145. if [ "$CHSH" = no ]; then
  146. return
  147. fi
  148. # If this user's login shell is already "zsh", do not attempt to switch.
  149. if [ "$(basename -- "$SHELL")" = "zsh" ]; then
  150. return
  151. fi
  152. # If this platform doesn't provide a "chsh" command, bail out.
  153. if ! command_exists chsh; then
  154. cat <<EOF
  155. I can't change your shell automatically because this system does not have chsh.
  156. ${BLUE}Please manually change your default shell to zsh${RESET}
  157. EOF
  158. return
  159. fi
  160. echo "${BLUE}Time to change your default shell to zsh:${RESET}"
  161. # Prompt for user choice on changing the default login shell
  162. printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
  163. "$YELLOW" "$RESET"
  164. read -r opt
  165. case $opt in
  166. y*|Y*|"") echo "Changing the shell..." ;;
  167. n*|N*) echo "Shell change skipped."; return ;;
  168. *) echo "Invalid choice. Shell change skipped."; return ;;
  169. esac
  170. # Check if we're running on Termux
  171. case "$PREFIX" in
  172. *com.termux*) termux=true; zsh=zsh ;;
  173. *) termux=false ;;
  174. esac
  175. if [ "$termux" != true ]; then
  176. # Test for the right location of the "shells" file
  177. if [ -f /etc/shells ]; then
  178. shells_file=/etc/shells
  179. elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
  180. shells_file=/usr/share/defaults/etc/shells
  181. else
  182. fmt_error "could not find /etc/shells file. Change your default shell manually."
  183. return
  184. fi
  185. # Get the path to the right zsh binary
  186. # 1. Use the most preceding one based on $PATH, then check that it's in the shells file
  187. # 2. If that fails, get a zsh path from the shells file, then check it actually exists
  188. if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
  189. if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
  190. fmt_error "no zsh binary found or not present in '$shells_file'"
  191. fmt_error "change your default shell manually."
  192. return
  193. fi
  194. fi
  195. fi
  196. # We're going to change the default shell, so back up the current one
  197. if [ -n "$SHELL" ]; then
  198. echo "$SHELL" > ~/.shell.pre-oh-my-zsh
  199. else
  200. grep "^$USERNAME:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
  201. fi
  202. # Actually change the default shell to zsh
  203. if ! chsh -s "$zsh"; then
  204. fmt_error "chsh command unsuccessful. Change your default shell manually."
  205. else
  206. export SHELL="$zsh"
  207. echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
  208. fi
  209. echo
  210. }
  211. main() {
  212. # Run as unattended if stdin is not a tty
  213. if [ ! -t 0 ]; then
  214. RUNZSH=no
  215. CHSH=no
  216. fi
  217. # Parse arguments
  218. while [ $# -gt 0 ]; do
  219. case $1 in
  220. --unattended) RUNZSH=no; CHSH=no ;;
  221. --skip-chsh) CHSH=no ;;
  222. --keep-zshrc) KEEP_ZSHRC=yes ;;
  223. esac
  224. shift
  225. done
  226. setup_color
  227. if ! command_exists zsh; then
  228. echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
  229. exit 1
  230. fi
  231. if [ -d "$ZSH" ]; then
  232. echo "${YELLOW}The \$ZSH folder already exists ($ZSH).${RESET}"
  233. if [ "$custom_zsh" = yes ]; then
  234. cat <<EOF
  235. You ran the installer with the \$ZSH setting or the \$ZSH variable is
  236. exported. You have 3 options:
  237. 1. Unset the ZSH variable when calling the installer:
  238. $(fmt_code "ZSH= sh install.sh")
  239. 2. Install Oh My Zsh to a directory that doesn't exist yet:
  240. $(fmt_code "ZSH=path/to/new/ohmyzsh/folder sh install.sh")
  241. 3. (Caution) If the folder doesn't contain important information,
  242. you can just remove it with $(fmt_code "rm -r $ZSH")
  243. EOF
  244. else
  245. echo "You'll need to remove it if you want to reinstall."
  246. fi
  247. exit 1
  248. fi
  249. setup_ohmyzsh
  250. setup_zshrc
  251. setup_shell
  252. printf %s "$GREEN"
  253. cat <<'EOF'
  254. __ __
  255. ____ / /_ ____ ___ __ __ ____ _____/ /_
  256. / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
  257. / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
  258. \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
  259. /____/ ....is now installed!
  260. EOF
  261. cat <<EOF
  262. Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.
  263. • Follow us on Twitter: $(fmt_underline https://twitter.com/ohmyzsh)
  264. • Join our Discord server: $(fmt_underline https://discord.gg/ohmyzsh)
  265. • Get stickers, shirts, coffee mugs and other swag: $(fmt_underline https://shop.planetargon.com/collections/oh-my-zsh)
  266. EOF
  267. printf %s "$RESET"
  268. if [ $RUNZSH = no ]; then
  269. echo "${YELLOW}Run zsh to try it out.${RESET}"
  270. exit
  271. fi
  272. exec zsh -l
  273. }
  274. main "$@"


配置.zshrc

ZSH_THEME=”ys” source ~/.zshrc

语法高亮

sudo apt install zsh-syntax-highlighting echo “source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh” >> ~/.zshrc source ~/.zshrc

  • 桌面美化 ```bash 安装优化工具 sudo apt install gnome-tweak-tool 使gnome支持插件扩展,以插件形式扩展应用 sudo apt install gnome-shell-extensions 使浏览器支持插件扩展,在浏览器打开按钮即可用 sudo apt install chrome-gnome-shell 插件网站 https://extensions.gnome.org 常用插件 Arcmenu、Clipboard indicator、Compiz alike windows effect、Coverflow alt-tab、Dash to dock、Dash to panel、Internet speed meter、Openweather、User themes

桌面、shell、图标和光标主题安装 网址:https://www.opendesktop.org/p/1013714/、https://www.pling.com/p/1312658/、https://www.gnome-look.org/browse/cat/ 方式一: 可通过ocs安装工具进行网页一键安装主题,下载路径(https://www.gnome-look.org/p/1136805/),下完之后用dpkg -i ocs.deb命令安装ocs工具(如果遇到依赖包问题用sudo apt-get install -f解决),安装好就可以在以上网址支持ocs安装主题的页面进行一键安装,再在优化工具中选择即可 方式二: 下载tar包,tar -xvf .tar 解压到/usr/share/icons、/usr/share/themes或者~/.themes、~/.icons目录下,再在优化工具中选

  1. <a name="21f4b796"></a>
  2. #### 3、安装工具
  3. ```bash
  4. 安装git
  5. sudo apt install git
  6. 安装vim
  7. sudo apt install vim
  8. 安装python2
  9. sudo apt install python
  10. 安装pip3
  11. sudo apt install python3-pip
  12. 安装ifconfig
  13. sudo apt install net-tools
  14. 安装curl
  15. sudo apt install curl

  1. 安装Typroa
  2. sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE
  3. wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
  4. sudo add-apt-repository 'deb https://typora.io/linux ./'
  5. sudo apt update
  6. sudo apt install typora

  1. 安装JetBrains全家桶
  2. https://www.jetbrains.com/toolbox-app/下载该工具进行无脑安装,注意解压后在非root用户启动

  1. 安装java8
  2. sudo apt update
  3. sudo apt install openjdk-8-jdk
  4. 如果安装了多个版本可通过命令设置默认版本
  5. sudo update-alternatives --config java
  6. 配置环境变量
  7. vim /etc/profile
  8. 添加
  9. #JAVA
  10. export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64(echo $JAVA_HOME可查看java安装目录)
  11. export JRE_HOME=${JAVA_HOME}/jre
  12. export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
  13. export PATH=${JAVA_HOME}/bin:$PATH
  14. 使配置生效
  15. source /etc/profile

  1. 安装maven
  2. sudo apt install maven
  3. 配置环境变量
  4. vim /etc/profile
  5. 添加
  6. #MAVEN
  7. MAVEN_HOME=/usr/share/maven(echo $MVN可查看maven安装目录)
  8. export MAVEN_HOME
  9. export PATH=${PATH}:${MAVEN_HOME}/bin
  10. 配置maven本地仓库和远程仓库
  11. vim /usr/share/maven/conf/settings.xml
  12. 添加
  13. <localRepository>/home/data/java-repository</localRepository>
  14. <mirror>
  15. <id>alimaven</id>
  16. <name>aliyun maven</name>
  17. <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  18. <mirrorOf>central</mirrorOf>
  19. </mirror>

  1. 安装redis可视化工具
  2. sudo snap install redis-desktop-manager

  1. 安装vscode和网易云音乐
  2. https://code.visualstudio.com/
  3. https://music.163.com/#/download下载.deb
  4. dpkg -i 或者 apt install *.deb命令安装

  1. 安装ssh
  2. apt install openssh-server
  3. 打开防火墙并允许ssh
  4. ufw enable
  5. ufw allow ssh
  6. 查看ssh运行状态
  7. service ssh status
  8. 连接远程服务器
  9. ssh user@ip

  1. 安装deepin-wine上的软件(QQ、微信等)
  2. wget -O- https://deepin-wine.i-m.dev/setup.sh | sh
  3. sudo apt-get install 包名(https://github.com/zq1997/deepin-winegithub上看有哪些软件包)

  1. 安装docker
  2. curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
  3. vim /etc/docker/daemon.json
  4. 添加docker国内镜像
  5. {
  6. "registry-mirrors": ["https://mj9kvemk.mirror.aliyuncs.com"]
  7. }
  8. 重启生效
  9. systemctl daemon-reload
  10. systemctl restart docker
  11. root用户如何使用docker
  12. 查看是否有docker用户组
  13. sudo cat /etc/group | grep docker
  14. 若没有进行添加
  15. sudo groupadd -g 999 docker(999为组iddocker为组名)
  16. 添加用户进docker
  17. sudo usermod -aG docker user
  18. 重启docker
  19. sudo systemctl restart docker
  20. 给权限
  21. sudo chmod a+rw /var/run/docker.sock
  22. 安装docker-compose
  23. sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  24. sudo chmod +x /usr/local/bin/docker-compose
  25. docker-compose --version

4、修改用户名

  1. 修改用户名,需要杀掉该用户所有的进程
  2. sudo pkill -u dan
  3. sudo pkill -9 -u dan
  4. 如果不行用root用户登陆操作,默认root是不能通过图形界面登陆的,需要修改配置:
  5. 设置root用户密码:sudo passwd root
  6. sudo vim /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf 添加greeter-show-manual-login= true
  7. sudo vim /etc/pam.d/gdm-autologin 注释掉auth required pam_succeed_if.so user != root quiet_success
  8. sudo vim /etc/pam.d/gdm-password 注释掉auth required pam_succeed_if.so user != root quiet_success
  9. sudo vim/root/.profile 添加tty -s && mesg n || true mesg n || true 将原来的mesg n 2> /dev/null || true注释掉
  10. 修改完重启选择root用户登陆即可,修改完再恢复配置
  11. 修改用户名
  12. usermod -l new_username old_username
  13. 修改home目录
  14. sudo usermod -d /home/new_username -m new_username
  15. 修改用户UID
  16. sudo usermod -u uid new_username
  17. 修改用户组名
  18. groupmod -n new_username old_username
  19. 查看用户信息
  20. id user_name

5、ubuntu笔记本设置关闭盖子不休眠

  1. sudo vim /etc/systemd/logind.conf
  2. #HandleLidSwitch=suspend -> HandleLidSwitch=ignore
  3. service systemd-logind restart