暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Ubuntu 20.04配置之旅

大海在途 2021-01-13
463

最近因为在学习机器学习,希望可以用Linux的系统上搭建一套学习环境。没想到还是遇到不少问题。这里记录一下方便自己,也希望能帮助到你。废话不多开始如下介绍。


0、必须工具VIM安装

Ubuntu系统安装完毕后,第一步当然是安装vim啦。

    sudo apt install vim


    1、切换APT源

    如果你在国内,请珍惜生命,建议更换apt源。否则你在后面非常非常痛苦的等待中老去……切记~~切记~~~

    用如下命令完成备份,打开源配置文件,然后清空后加入的下面源地址信息。这里我推荐使用清华源目前测试下来比较稳定。

      cd /etc/apt/
      sudo cp sources.list sources.list.bak
      sudo vim sources.list
      # 如果vi不熟悉的用户可以使用一下命令
      sudo gedit source.list 

      复制清华源至sources.list文件保存即可

        # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
        deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
        # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
        deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
        # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
        deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
        # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
        deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
        # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
        # 预发布软件源,不建议启用
        # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
        # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

        阿里源

          deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
          deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
          deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
          deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
          deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
          deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
          deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
          deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
          deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
          deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

          中科大源

            deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
            deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
            deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
            deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
            deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
            deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
            deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
            deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
            deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
            deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

            网易163源

              deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
              deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
              deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
              deb http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse
              deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
              deb-src http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
              deb-src http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
              deb-src http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
              deb-src http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse
              deb-src http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse

              PS:如果还有外部的源必须加入,且下载还比较慢,且你自己有梯子。可以参考如下设置apt的代理,来给apt的下载提速。这里的proxy是你自己的proxy的代理地址和端口,这里就不在赘述了。问问度娘吧~

                sudo apt-get -o Acquire::http::proxy="http://127.0.0.1:7890/" update



                二、安装git

                经常需要学习github上的优秀代码,git安装是必须的。至于怎么绑定github,非本文重点,这里不会讲到。安装非常简单,参考如下命令:

                  sudo apt install git

                  如果您卸载apt安装的包,可以通过以下命令:

                    sudo apt autoremove git

                    在安装git同时,同时会自动安装如下软件:(这些可以不用关心跳过)

                    git、git-man、liberror-perl

                    建议安装:

                    git-daemon-run | git-daemon-sysvinit、git-doc、 git-el、git-email、git-gui、gitk、gitweb、git-cvs、git-mediawiki、git-svn


                    个别搭建了代理的同学,可能会与遇到如下情况:

                      无法访问 'https://**********':Failed to receive SOCKS4 connect request ack.

                      这个是因为开启代理后导致git无法下载更新,这里将git的代理设置为本地代理即可。命令参考如下:

                        git config --global http.proxy 'socks5://127.0.0.1:7891'



                        三、安装python及环境

                        别问我为啥要用python,你开始学习机器学习的时候就会不知觉的用到。而且基础语法简单易学。数学函数库丰富…………巴拉巴拉…………


                        1、安装anaconda选择自己系统对应版本下载。我选的是Linux 64-bit*x86)Installer(529 MB)。

                        下载地址:https://www.anaconda.com/products/individual#Downloads

                        安装步骤如下:

                          cd ~/Downloads/
                          bash Anaconda3-2020.11-Linux-x86_64.sh


                          # 接下来一堆说明,问是否接受相关协议,yes即可
                          Do you accept the license terms? [yes|no]
                          [no] >>> yes
                          # 询问安装路径,直接回车即可
                          Anaconda3 will now be installed into this location:
                          ~/anaconda3
                            - Press ENTER to confirm the location
                            - Press CTRL-C to abort the installation
                            - Or specify a different location below
                          [~/anaconda3] >>> 
                          # 开始安装……
                          # 初始化conda,yes即可
                          Do you wish the installer to initialize Anaconda3
                          by running conda init? [yes|no]
                          [no] >>> yes

                          安装完毕会告诉你,如果你不想让conda随机启动,可以关闭自动启动。这里可以先忽略。

                            # 关闭命令
                            conda config --set auto_activate_base false

                            2、因为机器学习需要,我们需要用conda env一个python3.7的环境。

                              conda info --env # 查看conda env信息
                              conda create -n python3.7 # 创建新的env 
                              conda activate python3.7 # 切换到新的环境python3.7
                              conda deactivate # 退出当前env
                              # 默认conda的安装目录:~/anaconda3/envs/python3.7

                              3、安装python3.7

                                conda install python==3.7
                                # 这里会同时安装ca、openssl、certifi、wheel、pip、python、libffi、readline等包

                                4、jupyter notebook是非常方便的开发工具,可以分块执行。安装jupyter步骤如下:

                                  conda install jupyter
                                  # 这里会同时安装:pygments、notebook、entrypoints、markupsafe、ipython_genutils、terminado、ptyprocess、send2trash、sip、pandocfilters、nbconvert、ipykernel、glib、pickleshare、packaging、nest-asyncio、pyqt、ipywidgets、tornado、mistune、jedi、widgetsnbextension、async_generator、ipython、qt、six、pexpect、gstreamer、pyzmq、prometheus_client、jupyter_core、pyrsistent、webencodings、jupyter
                                  # 启动方式:
                                  cd ~/source
                                  # “.”表示,以当前目录为jupyter启动的根目录
                                  jupyter notebook .
                                  # 查看当前jupyter kernel路径
                                  jupyter kernelspec list

                                  5、安装python相关包,可以用如下命令,其他的包在自己需要的时候自行参考如下命令安装即可。

                                    conda install numpy
                                    conda install pandas



                                    四、安装R

                                    R语言,语法也比较简单。基础教程:https://www.w3cschool.cn/r/

                                    如果这里单独用apt安装可能存在包冲突问题,建议使用conda安装。另外必须关闭juypter notebook后再安装,否则可能出现jupyter无法使用R的问题。

                                      conda install r-essentials r-base
                                      # 这里会同时安装R的相关包:pkgs/r/linux-64/*、pkgs/main/linux-64/*
                                      # conda install -c r r-dplyry # 这个命令conda找不到



                                      五、安装shadowsocks

                                      懂的同学自行搜索,这里不是本文重点,不讲了……😂容我偷个懒哈



                                      六、U盘格式化

                                      这块内容可以忽略,我这边是因为刚好有块U盘,测试一下。

                                        # 1. 查看U盘盘符信息,一般是/dev/sdb1或/dev/sdc1
                                        cat /proc/mounts
                                        # 也可以用fdisk查看
                                        sudo fdisk -l
                                        # 2. 卸载U盘
                                        sudo umount dev/sdb1
                                        # 3. 格式化,有3种格式化方式
                                        sudo mkfs.ntfs /dev/sdb1
                                        sudo mkfs.ext4 /dev/sdb1 # Linux可以用这种
                                        sudo mkfs.vfat -F 32 dev/sdb1



                                        七、PyCharm安装

                                        安装PyCharm,python比较好用的IDE之一。个人还是比较推荐的,就是比较贵。经常就是jupyter notebook用于代码验证测试,PyCharm用于工程开发。

                                        1、下载PyCharm:https://www.jetbrains.com/pycharm/download

                                        2、安装步骤如下:

                                          tar xzf pycharm-*.tar.gz -C /opt/
                                          cd /opt/pycharm-*/bin
                                          sh pycharm.sh

                                          3、激活PyCharm:

                                          请从正版渠道购买~~

                                          以下信息仅供学习研究使用:

                                          ---------------------------------------------------------------

                                          3.1、网站http://www.lookdiv.com

                                          3.2、扫码获取最新钥匙

                                          3.3、激活前先关闭hosts

                                            sudo gedit /etc/hosts # 修改hosts文件
                                            0.0.0.0 account.jetbrains.com
                                            0.0.0.0 www.jetbrains.com

                                            ---------------------------------------------------------------

                                            4、启动PyCharm

                                              sh ~/app/PyCharm.sh



                                              八、安装常用的工具

                                              ubuntu下想玩QQ、微信、企业微信、钉钉。还是有些难度的。解决办法就是deepin wine安装。deepin大法好

                                              1、用Deepin的安装微信等软

                                              网站https://github.com/zq1997/deepin-wine

                                                # 安装deepin-wine 
                                                wget -O- https://deepin-wine.i-m.dev/setup.sh | sh
                                                # 安装微信
                                                sudo apt install deepin.com.wechat
                                                # 安装钉钉
                                                sudo apt install com.dingtalk.deepin

                                                下面给出常用软件列表,可以根据自己需要自行选择:

                                                应用
                                                包名
                                                微信com.qq.weixin.deepin
                                                QQ
                                                com.qq.im.deepin
                                                钉钉
                                                com.dingtalk.deepin
                                                阿里旺旺
                                                com.taobao.wangwang.deepin
                                                企业微信
                                                com.qq.wxwork.deepin
                                                QQ音乐com.qq.music.deepin
                                                QQ视频com.qq.video.deepin
                                                爱奇艺com.iqiyi.deepin

                                                也可以通过如下命令,搜索需要的安装包:

                                                  # 可以通过如下查询apt的可安装包,例如:
                                                  sudo apt search com.qq.*

                                                  2、字体问题。安装完后可能出现输入框、搜索框字体显示不正确,可以参考这边文章:https://blog.csdn.net/hymanjack/article/details/100168300

                                                  以下为我解决办法:

                                                  下载字体百度网盘链接:https://pan.baidu.com/s/1rkjkmGJlpdaijCEWi7TZIw) 提取码: btxw

                                                    # 解压后,复制下载字体至微信字体文件夹中
                                                    cp ~/下载/msyhttc/msyh.ttc ~/.deepinwine/Deepin-WeChat/drive_c/windows/Fonts
                                                    # 修改微信注册表信息,修改字体为msyh.ttc
                                                    gedit ~/.deepinwine/Deepin-WeChat/system.reg
                                                    # 修改为如下:
                                                    "MS Shell Dlg"="msyh"
                                                    "MS Shell Dlg 2"="msyh"
                                                    # 重新启动微信即可

                                                    3、图标deepin默认是开了一个小窗口,在里面显示非常不方便。这里推荐使用TopIncons工具,这样可以让app的图标显示在最上面的系统状态栏上。

                                                      # 安装xdotool
                                                      sudo apt install --no-install-recommends xdotool
                                                      # 安装小图标工具
                                                      cd ~/source
                                                      git clone https://github.com/phocean/TopIcons-plus.git
                                                      cd ~/source/TopIcons-plus
                                                      make install
                                                      # 或者替换make install命令如下,安装到指定目录中
                                                      sudo make install INSTALL_PATH=/usr/share/gnome-shell/extensions
                                                      # 安装完毕后,打开网址,然后在网页上打开开关即可
                                                      https://extensions.gnome.org/extension/1031/topicons/

                                                      4、高分辨率显示器窗口大小调整。

                                                      通过如下命令打开设置窗口,可以在里条在dpi大小,建议200

                                                        # 微信
                                                        WINEPREFIX=~/.deepinwine/Deepin-WeChat deepin-wine winecfg
                                                        # 钉钉
                                                        WINEPREFIX=~/.deepinwine/Deepin-Dding deepin-wine winecfg
                                                        # 软件需求其他辅助软件的安装方法
                                                        WINEPREFIX=~/.deepinwine/<容器名> deepin-wine "c:\\<文件名>"


                                                        九、安装Docker

                                                        可以参考如下地址:https://docs.docker.com/engine/install/ubuntu


                                                        1、设置存储仓库

                                                        1.1、更新apt package并安装需要的包

                                                          sudo apt-get update
                                                          sudo apt-get install \
                                                          apt-transport-https \
                                                          ca-certificates \
                                                          curl \
                                                          gnupg-agent \
                                                          software-properties-common

                                                          1.2、安装docker的官方的GPG密钥

                                                            curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

                                                            这里因为本次安装后出现如下报错,所以手工把gpg文件下载下来后,再执行。下载地址:https://download.docker.com/linux/ubuntu/gpg

                                                              sudo apt-key add gpg

                                                              GPG的密钥的相关命令

                                                                apt-key list # 列出已经保存在系统中的key
                                                                apt-key add keyname # 把下载的key添加到本地trusted数据库中
                                                                apt-key del keyname # 从本地trusted数据库删除key
                                                                apt-key update # 更新本地trusted数据库,删除过期没用的key

                                                                通过以上apt-key list命令找到如下信息,也可以通过搜索指纹最后8个字符命令,来验证是否拥有指纹9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88的密钥。

                                                                  sudo apt-key fingerprint 0EBFCD88


                                                                  # ================输出===================
                                                                  pub   rsa4096 2017-02-22 [SCEA]
                                                                  9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
                                                                  uid [ 未知 ] Docker Release (CE deb) <docker@docker.com>
                                                                  sub rsa4096 2017-02-22 [S]

                                                                  1.3、创建仓库

                                                                    sudo add-apt-repository \
                                                                    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
                                                                    $(lsb_release -cs) \
                                                                    stable"

                                                                    其中$(lsb_release -cs)返回的是当前系统的发行版本名词。例如我本地如此

                                                                      echo $(lsb_release -cs)


                                                                      # ================输出===================
                                                                      focal

                                                                      其中arch=******,这里的***可以替换,如下:

                                                                      amd64 => x86_64/amd64 (这里我选择这种)

                                                                      armhf => armhf

                                                                      amd64 => amd64


                                                                      2、安装Docker引擎

                                                                      2.1、更新apt package,并且安装最新版本的Docker 引擎和容器

                                                                        sudo apt-get update
                                                                        sudo apt-get install docker-ce docker-ce-cli containerd.io

                                                                        2.2、安装Docker Engine,在下列存储列表中选择可用版本

                                                                          apt-cache madison docker-ce


                                                                          # =================输出==================
                                                                          docker-ce | 5:20.10.2~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:20.10.1~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:20.10.0~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.14~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.13~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
                                                                          docker-ce | 5:19.03.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

                                                                          定版本安装,这里选择版本5:20.10.2~3-0~ubuntu-focal

                                                                            # sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
                                                                            sudo apt-get install docker-ce=5:20.10.2~3-0~ubuntu-focal docker-ce-cli=5:20.10.2~3-0~ubuntu-focal containerd.io


                                                                            # ===============输出==================
                                                                            containerd.io 已经是最新版 (1.4.3-1)。
                                                                            docker-ce-cli 已经是最新版 (5:20.10.2~3-0~ubuntu-focal)。
                                                                            docker-ce 已经是最新版 (5:20.10.2~3-0~ubuntu-focal)。

                                                                            2.3、验证Docker Engine是否安装成功,通过hello-world镜像测试

                                                                              sudo docker run hello-world


                                                                              # ===================输出====================
                                                                              Unable to find image 'hello-world:latest' locally
                                                                              latest: Pulling from library/hello-world
                                                                              0e03bdcc26d7: Pull complete
                                                                              Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
                                                                              Status: Downloaded newer image for hello-world:latest
                                                                              Hello from Docker!
                                                                              This message shows that your installation appears to be working correctly.
                                                                              To generate this message, Docker took the following steps:
                                                                              1. The Docker client contacted the Docker daemon.
                                                                              2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
                                                                              (amd64)
                                                                              3. The Docker daemon created a new container from that image which runs the
                                                                              executable that produces the output you are currently reading.
                                                                              4. The Docker daemon streamed that output to the Docker client, which sent it
                                                                              to your terminal.
                                                                              To try something more ambitious, you can run an Ubuntu container with:
                                                                              $ docker run -it ubuntu bash
                                                                              Share images, automate workflows, and more with a free Docker ID:
                                                                              https://hub.docker.com/
                                                                              For more examples and ideas, visit:
                                                                              https://docs.docker.com/get-started/



                                                                              十、安装截屏软件os-studio

                                                                              这个软件其实是直播软件,还是很强大的。支持功能很全,具体参考官网。

                                                                              官方地址:https://obsproject.com/wiki/install-instructions#linux

                                                                              参考知乎文章:https://zhuanlan.zhihu.com/p/149766028

                                                                                sudo add-apt-repository ppa:obsproject/obs-studio
                                                                                http://ppa.launchpad.net/obsproject/obs-studio/ubuntu/pool/main/o/obs-studio/obs-studio_26.1.1-0obsproject1~focal_amd64.deb
                                                                                sudo apt update
                                                                                sudo apt install obs-studio
                                                                                # 如果需要删除obs-studio,执行如下命令
                                                                                sudo apt-key list
                                                                                sudo apt-key del F425E228
                                                                                sudo add-apt-repository -r obs-studio



                                                                                十一、安装播放器,这里选择VLC

                                                                                  sudo apt install vlc



                                                                                  PS:踩过坑系列

                                                                                  1、第一个坑:

                                                                                  安装深度录屏工具,还是不要安装了。坑太多了,而且bug也很多。

                                                                                  如下步骤,到make无法执行下去了。现在已经删除了。

                                                                                    # git地址:https://github.com/manateelazycat/deepin-screen-recorder
                                                                                    cd ~/source
                                                                                    git clone https://github.com/manateelazycat/deepin-screen-recorder.git
                                                                                    cd deepin-screen-recorder
                                                                                    mkdir build
                                                                                    cd build
                                                                                    qmake ..
                                                                                    # 以下就是我在qmake的时候发现缺少的包,缺少什么安装什么
                                                                                    sudo apt-get install libxtst-dev
                                                                                    sudo apt-get install libxcb-util0-dev
                                                                                    sudo apt-get isntall libdtkwidget-dev
                                                                                    sudo apt-get install libdtkwm-dev
                                                                                    sudo apt-get install libprocps-dev
                                                                                    sudo apt-get install qt5-default
                                                                                    sudo apt-get install libc6 libgcc1 libgl1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5widgets5 libqt5x11extras5 libstdc++6 libx11-6 libxcb-util0 libxcb1 libxext6 libxtst6
                                                                                    make #这一步一直报错,提示无定义的方法。具体原因待查。
                                                                                    ./deepin-screen-recorder




                                                                                    文章转载自大海在途,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                                                                                    评论