Linux系统环境配置指南

目录

  • 一、系统
    • 1)Linux
    • 2)ROS
  • 二、软件
    • 1)Sogou
    • 2)Google
    • 3)VS code
    • 4)RoboWare Studio
    • 5)Typora
  • 三、配置
    • 1)ntpdate
    • 2)zsh
    • 3)Terminator

$ 安装配置Linux系统 = 疯狂碰壁		//整过的人都懂

几十次了也算有些经验了,正好笔者要重新安装配置一次,这里就同时做一下记录总结。网上教程比较多,笔者仅进行整理,未引用出处的地方,还请海涵~

一、系统

1)Linux

按照网上的教程安装吧,不同的电脑会遇到不同的问题,出现不同的奇奇怪怪的问题~

2)ROS

按照官方教程安装还好,具体问题具体查基本能解决。一般在进行到rosdep时会出错,这里推荐这位老哥的方法:离线rosdep,链接。

二、软件

1)Sogou

搜狗安装包下载地址为:http://pinyin.sogou.com/linux/。cd到文件目录下:

$ sudo dpkg -i [sogoupinyin_file_name].deb

由于Linux系统下搜狗输入法是在小企鹅输入法fcitx基础上安装的,需要安装fcitx,并在语言支持里面将ibus替换成fcitx,安装fcitx:

$ sudo apt install fcitx

若出现错误,输入修复命令:

$ sudo apt-get install -f

语言支持界面,点击应用到整个系统,重启电脑,更新输入法配置即可。
详细步骤,推荐该教程。

2)Google

一般都是64位版本,使用wget命令进行下载:

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

cd到下载目录使用dpkg命令进行安装:

$ sudo dpkg -i [google-chrome_file_name].deb

若出现dpkg:错误:另外一个进行已经为dpkg fronted加锁,重启电脑即可。
下面两个问题笔者未遇到:
有依赖关系使用命令:

$ sudo apt-get -f install

若点击运行,界面没有加载出来。

$ sudo gedit /opt/google/chrome/google-chrome

在最后一行exec -a “ 0 " " 0" " 0""HERE/chrome” "$@"最后加上 --no-sandbox $HOME

3)VS code

在官网下载deb包,cd到下载目录使用dpkg命令进行安装:

$ sudo dpkg -i [Vscode_file_name].deb

安装很简单,同时配置好的vscode环境尤为重要。安装插件:

  • ARM
  • Bracket Pair Colorizer
  • C/C++
  • C/C++ Snippets
  • C++ Intellisense
  • Chinese
  • clang-format
  • ESLint
  • Include Autocomplete
  • One Dark Pro
  • Prettier - Code formatter
  • Vetur

其中,C/C++配置工程环境。使用F1,打开命令选项,输入C/C++,选择C/C++:Edit configuration,生成c_cpp_properties.json配置文件,笔者的文件内容为:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/opt/ros/melodic/include/**",
                "/usr/include/**",
                "/usr/local/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

这样之后,程序中就不会有波浪线了,变量和函数的声明定义也可跳转。
同时,代码格式化用到clang-format,除了在Vscode中安装,还需终端安装:

$ sudo apt-get install clang-format

之后在工作空间下创建文件.clang-format,配置文件:

# 基于那个配置文件
BasedOnStyle: LLVM
# 访问说明符的偏移(public private)
AccessModifierOffset: -4
# 括号之后,水平对齐参数: Align DontAlign AlwaysBreak
AlignAfterOpenBracket: Align
# 连续的赋值时,对齐所有的等号
AlignConsecutiveAssignments: true
# 连续声明时,对齐所有声明的变量名
AlignConsecutiveDeclarations: true
# 左对齐换行(使用反斜杠换行)的反斜杠 
AlignEscapedNewlinesLeft: true
# 水平对齐二元和三元表达式的操作数 
AlignOperands: true
# 对齐连续的尾随的注释  
AlignTrailingComments: true
# 允许函数声明的所有参数在放在下一行  
AllowAllParametersOfDeclarationOnNextLine: true
# 允许短的块放在同一行  
AllowShortBlocksOnASingleLine : false
# 允许短的case标签放在同一行
AllowShortCaseLabelsOnASingleLine: false
# 允许短的函数放在同一行: None, InlineOnly(定义在类中), Empty(空函数), Inline(定义在类中,空函数), All 
AllowShortFunctionsOnASingleLine: Empty
# 是否允许短if单行 If true, if (a) return; 可以放到同一行
AllowShortIfStatementsOnASingleLine: false
# 允许短的循环保持在同一行   
AllowShortLoopsOnASingleLine: false 
# 总是在定义返回类型后换行(deprecated)   
AlwaysBreakAfterDefinitionReturnType: None
# 每行字符的限制,0表示没有限制  
ColumnLimit: 100
# 描述具有特殊意义的注释的正则表达式,它不应该被分割为多行或以其它方式改变
CommentPragmas: '^ IWYU pragma:'
# 语言: None Cpp Java Objc Protp
Language: Cpp 
#指针的*的挨着哪边
PointerAlignment: Right
#缩进宽度
IndentWidth: 4
# 连续的空行保留几行
MaxEmptyLinesToKeep: 1
# 在 @property 后面添加空格, \@property (readonly) 而不是 \@property(readonly).
ObjCSpaceAfterProperty: true
# OC block后面的缩进
ObjCBlockIndentWidth: 4
# 是否允许短方法单行
AllowShortFunctionsOnASingleLine: false
# 换行的时候对齐操作符
#AlignOperands: true
# 中括号两边空格 [] 
SpacesInSquareBrackets: true
# 小括号两边添加空格
SpacesInParentheses : false
#等号两边的空格
SpaceBeforeAssignmentOperators: true
# 容器类的空格 例如 OC的字典
SpacesInContainerLiterals: true
#缩进
IndentWrappedFunctionNames: true
#在block从空行开始
KeepEmptyLinesAtTheStartOfBlocks: true
#在构造函数初始化时按逗号断行,并以冒号对齐
BreakConstructorInitializersBeforeComma: true
#括号后添加空格
SpaceAfterCStyleCast: false
# 允许排序#include, 造成编译错误
# SortIncludes: true 
# 缩进case 标签
IndentCaseLabels: true 
#tab键盘的宽度
TabWidth: 4
UseTab: Never

4)RoboWare Studio

一般情况下使用Vscode就足够了,但如果想进行远程调试,涉及程序的修改,就需要用到RoboWare Studio的部署功能了。下载deb包,好像不能从官网下载了,网上应该有资源,下载完成后,cd到下载目录使用dpkg命令进行安装:

$ sudo dpkg -i [RoboWare_Studio_file_name].deb

5)Typora

Markdown文档编写,下载deb包,cd到下载目录使用dpkg命令进行安装:

$ sudo dpkg -i [Typora_file_name].deb

可能存在未安装依赖的问题,根据终端提示安装依赖即可。

三、配置

1)ntpdate

安装双系统会存在windows和linux时间不同步的问题,解决方法:

$ sudo apt-get install ntpdate				//在ubuntu16.04下更新本地时间
$ sudo ntpdate time.windows.com
$ sudo hwclock --localtime --systohc		//将本地时间更新到硬件上

重启,进入windows时间就改变回来了。

2)zsh

如果你喜欢敲键盘的感觉,完全没必要配置zsh,zsh配置好后输入感极差~
安装的话,打开终端,输入:

$ sudo apt-get install zsh

安装oh-my-zsh,但是安装时会存在网络的问题,这里推荐使用脚本文件(来源)安装。新建文件install_oh_my_zsh.sh,文件内容:

#!/bin/sh
#
# This script should be run via curl:
#   sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# or via wget:
#   sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# or via fetch:
#   sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#
# As an alternative, you can first download the install script and run it afterwards:
#   wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
#   sh install.sh
#
# You can tweak the install behavior by setting variables when running the script. For
# example, to change the path to the Oh My Zsh repository:
#   ZSH=~/.zsh sh install.sh
#
# Respects the following environment variables:
#   ZSH     - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
#   REPO    - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
#   REMOTE  - full remote URL of the git repo to install (default: GitHub via HTTPS)
#   BRANCH  - branch to check out immediately after install (default: master)
#
# Other options:
#   CHSH       - 'no' means the installer will not change the default shell (default: yes)
#   RUNZSH     - 'no' means the installer will not run zsh after the install (default: yes)
#   KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
#
# You can also pass some arguments to the install script to set some these options:
#   --skip-chsh: has the same behavior as setting CHSH to 'no'
#   --unattended: sets both CHSH and RUNZSH to 'no'
#   --keep-zshrc: sets KEEP_ZSHRC to 'yes'
# For example:
#   sh install.sh --unattended
# or:
#   sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
#
set -e
# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
# Other options
CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
command_exists() {
	command -v "$@" >/dev/null 2>&1
}
error() {
	echo ${RED}"Error: $@"${RESET} >&2
}
underline() {
	echo "$(printf '\033[4m')$@$(printf '\033[24m')"
}
setup_color() {
	# Only use colors if connected to a terminal
	if [ -t 1 ]; then
		RED=$(printf '\033[31m')
		GREEN=$(printf '\033[32m')
		YELLOW=$(printf '\033[33m')
		BLUE=$(printf '\033[34m')
		BOLD=$(printf '\033[1m')
		RESET=$(printf '\033[m')
	else
		RED=""
		GREEN=""
		YELLOW=""
		BLUE=""
		BOLD=""
		RESET=""
	fi
}
setup_ohmyzsh() {
	# Prevent the cloned repository from having insecure permissions. Failing to do
	# so causes compinit() calls to fail with "command not found: compdef" errors
	# for users with insecure umasks (e.g., "002", allowing group writability). Note
	# that this will be ignored under Cygwin by default, as Windows ACLs take
	# precedence over umasks except for filesystems mounted with option "noacl".
	umask g-w,o-w
	echo "${BLUE}Cloning Oh My Zsh...${RESET}"
	command_exists git || {
		error "git is not installed"
		exit 1
	}
	if [ "$OSTYPE" = cygwin ] && git --version | grep -q msysgit; then
		error "Windows/MSYS Git is not supported on Cygwin"
		error "Make sure the Cygwin git package is installed and is first on the \$PATH"
		exit 1
	fi
	git clone -c core.eol=lf -c core.autocrlf=false \
		-c fsck.zeroPaddedFilemode=ignore \
		-c fetch.fsck.zeroPaddedFilemode=ignore \
		-c receive.fsck.zeroPaddedFilemode=ignore \
		--depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
		error "git clone of oh-my-zsh repo failed"
		exit 1
	}
	echo
}
setup_zshrc() {
	# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
	# with datestamp of installation that moved them aside, so we never actually
	# destroy a user's original zshrc
	echo "${BLUE}Looking for an existing zsh config...${RESET}"
	# Must use this exact name so uninstall.sh can find it
	OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
	if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
		# Skip this if the user doesn't want to replace an existing .zshrc
		if [ $KEEP_ZSHRC = yes ]; then
			echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
			return
		fi
		if [ -e "$OLD_ZSHRC" ]; then
			OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
			if [ -e "$OLD_OLD_ZSHRC" ]; then
				error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
				error "re-run the installer again in a couple of seconds"
				exit 1
			fi
			mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
			echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
				"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
		fi
		echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
		mv ~/.zshrc "$OLD_ZSHRC"
	fi
	echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
	sed "/^export ZSH=/ c\\
export ZSH=\"$ZSH\"
" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
	mv -f ~/.zshrc-omztemp ~/.zshrc
	echo
}
setup_shell() {
	# Skip setup if the user wants or stdin is closed (not running interactively).
	if [ $CHSH = no ]; then
		return
	fi
	# If this user's login shell is already "zsh", do not attempt to switch.
	if [ "$(basename "$SHELL")" = "zsh" ]; then
		return
	fi
	# If this platform doesn't provide a "chsh" command, bail out.
	if ! command_exists chsh; then
		cat <<-EOF
			I can't change your shell automatically because this system does not have chsh.
			${BLUE}Please manually change your default shell to zsh${RESET}
		EOF
		return
	fi
	echo "${BLUE}Time to change your default shell to zsh:${RESET}"
	# Prompt for user choice on changing the default login shell
	printf "${YELLOW}Do you want to change your default shell to zsh? [Y/n]${RESET} "
	read opt
	case $opt in
		y*|Y*|"") echo "Changing the shell..." ;;
		n*|N*) echo "Shell change skipped."; return ;;
		*) echo "Invalid choice. Shell change skipped."; return ;;
	esac
	# Check if we're running on Termux
	case "$PREFIX" in
		*com.termux*) termux=true; zsh=zsh ;;
		*) termux=false ;;
	esac
	if [ "$termux" != true ]; then
		# Test for the right location of the "shells" file
		if [ -f /etc/shells ]; then
			shells_file=/etc/shells
		elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
			shells_file=/usr/share/defaults/etc/shells
		else
			error "could not find /etc/shells file. Change your default shell manually."
			return
		fi
		# Get the path to the right zsh binary
		# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
		# 2. If that fails, get a zsh path from the shells file, then check it actually exists
		if ! zsh=$(which zsh) || ! grep -qx "$zsh" "$shells_file"; then
			if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -1) || [ ! -f "$zsh" ]; then
				error "no zsh binary found or not present in '$shells_file'"
				error "change your default shell manually."
				return
			fi
		fi
	fi
	# We're going to change the default shell, so back up the current one
	if [ -n "$SHELL" ]; then
		echo $SHELL > ~/.shell.pre-oh-my-zsh
	else
		grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
	fi
	# Actually change the default shell to zsh
	if ! chsh -s "$zsh"; then
		error "chsh command unsuccessful. Change your default shell manually."
	else
		export SHELL="$zsh"
		echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
	fi
	echo
}
main() {
	# Run as unattended if stdin is closed
	if [ ! -t 0 ]; then
		RUNZSH=no
		CHSH=no
	fi
	# Parse arguments
	while [ $# -gt 0 ]; do
		case $1 in
			--unattended) RUNZSH=no; CHSH=no ;;
			--skip-chsh) CHSH=no ;;
			--keep-zshrc) KEEP_ZSHRC=yes ;;
		esac
		shift
	done
	setup_color
	if ! command_exists zsh; then
		echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
		exit 1
	fi
	if [ -d "$ZSH" ]; then
		cat <<-EOF
			${YELLOW}You already have Oh My Zsh installed.${RESET}
			You'll need to remove '$ZSH' if you want to reinstall.
		EOF
		exit 1
	fi
	setup_ohmyzsh
	setup_zshrc
	setup_shell
	printf "$GREEN"
	cat <<-'EOF'
		         __                                     __
		  ____  / /_     ____ ___  __  __   ____  _____/ /_
		 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
		/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
		\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
		                        /____/                       ....is now installed!
	EOF
	cat <<-EOF
		Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.
		• Follow us on Twitter: $(underline https://twitter.com/ohmyzsh)
		• Join our Discord server: $(underline https://discord.gg/ohmyzsh)
		• Get stickers, shirts, coffee mugs and other swag: $(underline https://shop.planetargon.com/collections/oh-my-zsh)
	EOF
	printf "$RESET"
	if [ $RUNZSH = no ]; then
		echo "${YELLOW}Run zsh to try it out.${RESET}"
		exit
	fi
	exec zsh -l
}
main "$@"

运行脚本文件:

$ sh install_oh_my_zsh.sh

选择y,会替换默认的shell。或者使用命令替换:

$ chsh -s /bin/zsh

重启电脑,可以看到终端已发生了改变,但是这还并不是zsh的完全体,需要添加插件。

  • 自动补全插件
$ git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

在终端打开.zshrc文件:

$ sudo gedit .zshrc

在plugins=(git)的括号中添加zsh-autosuggestions,效果如下:

$ plugins=(git zsh-autosuggestions)
  • 高亮插件
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

打开.zshrc文件添加zsh-syntax-highlighting。

3)Terminator

添加终端分屏功能,输入:

$ sudo apt-get install terminator

网上说需要添加源,但成功与否有点玄学~

目前笔者只安装了这些,后续持续更新~

你可能感兴趣的:(linux,ubuntu)