Skip to main content

Tiu MoAbout 7 min

# 安装ubuntu系统

## 0.准备工作

### 0.1 下载镜像及启动盘制作工具

```shell
# 下载链接 
https://ubuntu.com/download/desktop  # Ubuntu 镜像,LTS 表示长期支持版,两年更新一次
https://cn.ultraiso.net/xiazai.html  # UltralISO
http://www.dayanzai.me/ultraiso.html
https://www.ventoy.net/cn/index.html  # Ventoy
1. 下载软件解压

0.1.制作Ubuntu启动盘

u盘 需格式化为FAT32格式(有些U盘不支持,可能出问题)

使用UltralISO制作ubuntu安装u盘参考链接:用UltraISO制作Ubuntu16|18|20.04 U盘启动盘open in new window

建议制作UEFI启动盘,后面会少很多事,而且启动时可以选择启动系统

U盘错误变为4M的解决方法

step1:cmd进入命令窗口; step2:输入命令 Diskpart 进入磁盘管理; step3:list disk 查看磁盘信息; step4:select disk 1 根据实际情况选择问题u盘; step5:clean 清理重置;

通过以上步骤后磁盘完全重置,但没有分区,需要重新分区 左边计算机右键,选择管理进入计算机管理,可以看到U盘未分配,即未分区。 右键磁盘1即U盘选择新建简单卷,全都下一步即可。

步骤如下
  1. 使用 UltralISO 打开 Ubuntu ISO文件
  2. 点击 “启动→🛡️写入硬盘映像...”
  3. 写入方式选择USB-HDD+或者USB-HDD均可(一般用USB-HDD+) a.【隐藏启动分区最好选择无,省的以后格式化麻烦】 b.【刻录校验可要可不要】
  4. 点击 “便捷启动→写入新的驱动器引导扇区→Syslinux” a. 【这一步的作用是让开机启动时能够以U盘启动 Linux安装系统,否则U盘就相当于是存了数据而不是启动盘】 b. 【重要,这里我遇到了找到多于1个分区,而无法写入Syslinux】 i. 解决办法为在便捷启动里先选择分区表编辑器 ii. 选择第一项,然后将其至为活动状态,然后写入(提示写入成功后点击返回) iii. 注意隐藏状态不要是YES
  5. 点击“写入” ,选择“是”

0.2.前置工作

  1. 打开“磁盘管理”,压缩系统卷。
  2. 启动时按 (DELL、华硕->F2) 键进入 BIOS设置。确保 BIOS 设为 UEFI,禁用 Legacy option ROMSsecure boot
  3. 启动时进入BIOS(DELL->F12),选择UEFI -> USB启

1. 安装Ubuntu系统

1.1 安装系统

安装时有选项

  • ubuntu
    
  • ubuntu(safa graphics) # 选这个
    

然后跟随ubuntu安装指引安装(建议使用英文)

1.2 配置系统

$ sudo apt-get install vim  # vim 编辑所需
$ sudo apt-get install net-tools  # 网络相关命令所需 
# $ sudo apt-get install screen  # 远程离线运行所需

$ sudo apt install python3-pip  # pip 安装所需
$ sudo apt-get install python3-distutils  # pip 的支持模块(可选)

## 安装中文输入法(可选, 搜狗输入法更好用,但是安装有几率失败)
$ sudo apt install ibus-libpinyin 
$ sudo apt install ibus-clutter
# 然后到设置中添加输入法,如果不成功reboot再添加

# ssh 连接
$ sudo apt-get install openssh-server  # 安装ssh服务端
$ sudo apt-get install openssh-client  # 安装ssh客户端(可选)
$ sudo /etc/init.d/ssh start  # 启动ssh服务

$ ip a 'or' $ ifconfig. # 查看ip地址
# ssh 连接
$ ssh username@ip_address

# 若重装服务器链接报错,删除 key in /Users/your_name/.ssh/known_hosts 即可
$ ssh-keygen -R 172.16.152.209(your_host_ip)

# 卸载不需要的库
$ sudo apt-get remove pk_name(需要卸载的库名称)  # 卸载 pk_name

1.3 安装conda

# 下载地址:
'https://www.anaconda.com/products/individual#download-section'  # 官网地址->下载速可能较慢
'https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/'  # 清华大学开源软件镜像站

# 安装
cd your_software_dir  # eg: /home/leng/Downloads/
bash Anaconda3-2021.05-Linux-x86_64.sh
# 然后按终端中提示安装
# 可以安装到/opt目录,然后设置777,多用户共享

# 修改环境变量(可选)
vim ~/.bashrc
'add' export PATH="/home/leng/anaconda3/bin:$PATH"  # 修改为anaconda3的安装路径
source ~/.bashrc

# 检查是否安装成功/查看版本
conda --version 'or' $ conda -V

# 添加路径无反应,重启试试

多用户

su # 首先进入root用户安装anaconda至/opt/anaconda
groupadd anaconda # 创建anaconda组
adduser "username" anaconda # 将需要的用户添加至anaconda组
chgrp -R anaconda /opt/anaconda # 移交目录管理权
chmod 770 -R /opt/anaconda # 设置读写权限
chmod g+s /opt/anaconda # 设置组继承
chmod g+s `find /opt/anaconda/ -type d` # 设置子目录组继承
chmod g-w /opt/anaconda/envs # 关闭共享环境的写入权限
source /opt/anaconda/bin/activate # root用户下启动anaconda环境
conda create -n share3.7 python=3.7 # 创建共享环境

Conda增加清华的镜像(不推荐)

源网络有问题不报错,推荐装的时候加 -c

# 运行下面的代码 (后添加的通道优先级更高)
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/

或直接把下面文字拷贝到 ~/.condarc中 (越靠前的优先级越高)

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/peterjc123/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

conda config --set show_channel_urls yes 显示通道地址
conda config --show-sources 查看现有源
conda config --remove channels defaults 删除默认源
conda config --remove-key channels

conda info --env            查看已经配置的环境
conda activate name     进入环境
conda deactivate 退出环境

conda create -n name python=3.6 创建环境
conda remove –n name --all            删除环境
conda create -n xiaolv --clone xiaolvshijie 复制环境
conda config --remove channels https://pypi.doubanio.com/simple/

conda/pip  list        查看库
conda remove name      移除包

pip install -r requirements.txt
conda install --yes --file requirements.txt

CUDA_HOME='/usr/local/cuda-10.0:'

export TORCH_CUDA_ARCH_LIST="7.5"
unset TORCH_CUDA_ARCH_LIST

conda env create -f mm.yml

Python包管理工具 pip镜像 可以每次安装时加-i参数 (或使用alias命令)。

注意,simple不能少, 是https而不是 http。

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

升级 pip 到最新的版本 (>=10.0.0) 后进行永久配置:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

另一种安装方式

$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2019.10-Linux-x86_64.sh #从清华源上下载安装包
$ chmod +x Anaconda3-2019.10-Linux-x86_64.sh #添加执行权限
#如果想多用户使用推荐安装到/opt/anaconda3 目录中(需要sudo权限)
$ sudo bash Anaconda3-2019.10-Linux-x86_64.sh -b -p /opt/anaconda3 #执行安装
$ echo -e '. /opt/anaconda3/etc/profile.d/conda.sh \n conda activate' |tee -a ~/.bashrc  #添加环境变量到当前用户的".bashrc"文件中

#其他用户想使用anaconda也是执行上一条相同的命令即可
$ source ~/.bashrc #使环境变量生效.

1.4 Ubuntu 安装 Pycharm(可选)

下载链接:Get Your Educational Tool - JetBrainsopen in new window

$ cd your_software_dir  # eg: /home/leng/Downloads/
$ tar -zxvf pycharm-edu-2021.1.2.tar.gz pycharm/  # 解压文件
$ sudo mv pycharm/ /opt/pycharm/

$ sh /opt/pycharm/pycharm-edu-2021.1.2/bin/pycharm.sh  # 启动 PyCharm(在ubuntu终端)

# 然后在启动页面点击设置icon选择‘Create Desktop Entry...’ -> 创建桌面图标

cuda 安装

简单说一下 anaconda 和 cuda 的安装:

现在的话就是服务器里有 anaconda 安装包和cuda-11.1 了。因为 Ubuntu 现在版本是 20.了所以cuda-10.就不兼容了。

大家进入自己账号之后, 先执行 ln -s /usr/local/cuda-11.1 /home/你的名字/cuda 这一步就是给 cuda-11.1 在你的账户下面创建一个快捷方式,至于为什么之后再说。

然后 vim ~/.bashrc 进入后在最下面添加两行

export PATH=/home/你的名字/cuda/bin:$PATH
export LD_LIBRARY_PATH=/home/你的账户/cuda/lib64:$LD_LIBRARY_PATH

这里是告诉服务器去哪里找 cuda。然后 source ~/.bashrc 最后 nvcc -V 检验一下是否成功

创建快捷方式是为了方便的更换 cuda 版本,比如现在是 11.1 要变成 11.3 版本的话执行 ln -s /usr/local/cuda-11.3 /home/你的账户/cuda 就行了 这样你不用每次改变环境变量。而且每个账户都是独立的我这里改了不影响其他人。

Anaconda 安装包在/home/gaorui 这里有一个,当然你也可以自己重新下, 然后把安装包复制到自己目录下 然后 ./Anaconda3-2021.05-Linux-x86_64.sh 一路 yes 就行了 source ~/.bashrc 如果 出现(base)就说明成功了。

.bashrc 这个文件呢就是在你启动个人账户时会自动执行,就会把你相比于他人不同的设置更改一下。 Export 指令就是改变环境变量也就是路径。

还有就是毅炜现在给你们的是 sudo 权限,如果还是不方便的话就再升级为 root 权限。

https://www.nvidia.cn/Download/index.aspx?lang=cnopen in new window

https://developer.nvidia.com/cuda-downloadsopen in new window

显示驱动

sudo apt install lightdm
sudo dpkg-reconfigure lightdm

参考链接

  1. 安装ubuntu(双系统选择'其它选项')如何在戴尔PC上作为双启动安装Ubuntu和Windows 8或10 | Dell 中国open in new window
  2. 安装显卡驱动Ubuntu安装显卡驱动详细步骤_m0_54792870的博客-CSDN博客open in new window
  3. 安装cuda https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_localopen in new window