ubuntu开发环境配置

 

修改软件源

  1. Ubuntu 默认的软件源是境外的,速度上会有些问题,我们可以在「Software & Updates」(软件和更新)中选择国内的镜像。

  2. 还可以直接修改配置文件 https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.775b1b11o2W9u7

更新系统软件

sudo apt update
sudo apt upgrade
sudo apt autoremove
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

bash基本配置

```shell
# vim ~/.bashrc
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\] '
```

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服务

  1. 安装
sudo apt update
sudo apt install openssh-server

ssh免密登录失败

  1. win10产生密钥

  2. Ubuntu 添加密钥到 authorized_keys

  3. 修改配置文件:/etc/ssh/sshd_config

     StrictModes no
    
     PubkeyAuthentication yes
    
     AuthorizedKeysFile      .ssh/authorized_keys
    
     PasswordAuthentication yes
    
  4. 登录

     ssh -i ~/.ssh/id_rsa xxx@192.168.1.103
    

git

  1. 安装
sudo apt update
sudo apt install git
sudo apt install cmake
  1. 配置

git配置

静态IP

  1. VirtualBox安装完Ubuntu后,默认应该是开启一块网卡,连接方式根据宿主电脑的连接方式来(如果物理机是通过有线上网,那么需要使用NAT网络连接方式,如果是无线网络,那么需要使用桥接方式上网),该网卡负责虚拟机的上网。
  2. 查看网卡名字

     ifconfig
    
  3. 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
    
  4. sudo netplan apply

ubuntu中安装samba文件服务

参考链接

  1. 安装

     sudo apt update
     sudo apt install samba samba-common -y
    
  2. 配置内容

     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
    
  3. 添加用户

     sudo smbpasswd -a wtp
    
  4. 重启服务

     sudo /etc/init.d/smbd restart
    

关闭终端提示音

  1. 在终端输入: sudo vim /etc/inputrc 。
  2. 找到 # set bell-style none 这一行,去掉前面的注释符号和空格。
  3. 重启终端

docker

  1. 安装docker
#1. 安装
curl -fsSL https://mirrors.ustc.edu.cn/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"
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 8G /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