ubuntu CUDA9.0 _2

ubuntu 同时安装cuda8.0与cuda9.0,cuda9.1

部分代码需要cuda8.0,部分需要cuda9.0 于是萌生了同时安装2个版本的想法。

0 前提:

ubuntu 16.04. x86_64

已经安装 cuda 8.0:

[plain] view plain copy
  1. nvcc –version  
  2. nvcc: NVIDIA (R) Cuda compiler driver  
  3. Copyright (c) 2005-2016 NVIDIA Corporation  
  4. Built on Tue_Jan_10_13:22:03_CST_2017  
  5. Cuda compilation tools, release 8.0, V8.0.61  

1 下载 cuda 9.0:

cuda 9.0



2.  在自己的目录下为cuda9.0新建一个文件夹,用于存放  cuda_9.0.176_384.81_linux.run 与后面的sample。

3.  生成可执行文件 

[plain] view plain copy
  1. chmod 777 <span>cuda_9.0.176_384.81_linux.run</span>  

4. 执行:

[plain] view plain copy
  1. ./cuda_9.0.176_384.81_linux.run  

5. 一些安装过程:

(因为我需要保留cuda8.0 于是暂时不做软连接 )

[plain] view plain copy
  1. Do you want to install a symbolic link at /usr/local/cuda?  
  2. (y)es/(n)o/(q)uit: n   

[plain] view plain copy
  1. Do you accept the previously read EULA?  
  2. accept/decline/quit: accept  
  3.   
  4. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?  
  5. (y)es/(n)o/(q)uit: y  
  6.   
  7. Do you wish to run the installation with 'sudo'?  
  8. (y)es/(n)o: y  
  9.   
  10. Please enter your password:   
  11. Do you want to install the OpenGL libraries?  
  12. (y)es/(n)o/(q)uit [ default is yes ]:   
  13.   
  14. Do you want to run nvidia-xconfig?  
  15. This will update the system X configuration file so that the NVIDIA X driver  
  16. is used. The pre-existing X configuration file will be backed up.  
  17. This option should not be used on systems that require a custom  
  18. X configuration, such as systems with multiple GPU vendors.  
  19. (y)es/(n)o/(q)uit [ default is no ]:    
  20.   
  21. Install the CUDA 9.0 Toolkit?  
  22. (y)es/(n)o/(q)uit: y  
  23.   
  24. Enter Toolkit Location  
  25.  [ default is /usr/local/cuda-9.0 ]:   
  26.   
  27. Do you want to install a symbolic link at /usr/local/cuda?  
  28. (y)es/(n)o/(q)uit: n   
  29.   
  30. Install the CUDA 9.0 Samples?  
  31. (y)es/(n)o/(q)uit: y  
  32.   
  33. Enter CUDA Samples Location  
  34.  [ default is /home/linlf ]: /home/linlf/tools/cuda9.0  


5报错:

Itappears that an X server is running. Please exit X beforeinstallation. If you're sure that X is not running, but are gettingthis error, please delete any X lock files in /tmp.



6 参考 https://blog.csdn.net/cc1949/article/details/78491781

6.1 查看 Xpsaux | grep X

6.2 关闭X. light类型的桌面系统

      Sudo /etc/init.d/lightdm stop





6.4 接着按照第一步第方法继续安装cuda9.0

7  修改配置文件:

export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
export LIBRARY_PATH="/usr/local/cuda/lib64:$LIBRARY_PATH"

8。 配置文件生效:

source ~/.bashrc

9。然后就可以切换8.09.0了:

[plain] view plain copy
  1. rm –rf /usr/local/cuda  
  2.   
  3. ln -s /usr/local/cuda-9.0 /usr/local/cuda  


10。若别的用户需要使用到。同样如上切换。

11。 最后进入 cuda9.0samplemake所有第例子.


(后续:)

12 若需要再安装cuda9.1: 会报错:


[plain] view plain copy
  1. 15 Using built-in stream user interface  
  2. 16 -> Detected 56 CPUs online; setting concurrency level to 32.  
  3. 17 -> License accepted by command line option.  
  4. 18 -> Installing NVIDIA driver version 387.26.  
  5. 19 -> The NVIDIA driver appears to have been installed previously using a different installer. To prevent potential conflicts, it is recommended either to update the  
  6.     existing installation using the same mechanism by which it was originally installed, or to uninstall the existing installation before installing this driver. 20   
  7. 21 Please review the message provided by the maintainer of this alternate installation method and decide how to proceed:  
  8. 22   
  9. 23 The package that is already installed is named nvidia-384.  
  10. 24   
  11. 25 You can upgrade the driver by running:  
  12. 26 `apt-get install nvidia-384 nvidia-modprobe nvidia-settings`  
  13. 27   
  14. 28 You can remove nvidia-384, and all related packages, by running:  
  15. 29 `apt-get remove --purge nvidia-384 nvidia-modprobe nvidia-settings`  
  16. 30   
  17. 31 This package is maintained by NVIDIA (cudatools@nvidia.com).  
  18. 32   
  19. 33   
  20. 34 (Answer: Abort installation)  
  21. 35 ERROR: The installation was canceled due to the availability or presence of an alternate driver installation. Please see /var/log/nvidia-installer.log for more de  
  22.    tails.  

意思是CUDA    驱动版本冲突:

CUDA8.0依赖的是384版本驱动,而CUDA9.1依赖的是387版本驱动,因此需要更新/卸载384驱动。

卸载:

[plain] view plain copy
  1. sudo apt-get remove --purge nvidia-384 nvidia-modprobe nvidia-settings  

卸载细节:

[plain] view plain copy
  1. lin@cc:~/tools/cuda9.1$ sudo apt-get remove --purge nvidia-384 nvidia-modprobe n  
  2. vidia-settingsReading package lists... Done  
  3. Building dependency tree         
  4. Reading state information... Done  
  5. The following packages were automatically installed and are no longer required:  
  6.   apt-xapian-index aptitude-common cuda-command-line-tools-8-0 cuda-core-8-0  
  7.   cuda-cublas-8-0 cuda-cublas-dev-8-0 cuda-cudart-8-0 cuda-cudart-dev-8-0  
  8.   cuda-cufft-8-0 cuda-cufft-dev-8-0 cuda-curand-8-0 cuda-curand-dev-8-0  
  9.   cuda-cusolver-8-0 cuda-cusolver-dev-8-0 cuda-cusparse-8-0 cuda-cusparse-dev-8-0  
  10.   cuda-documentation-8-0 cuda-driver-dev-8-0 cuda-license-8-0 cuda-misc-headers-8-0  
  11.   cuda-npp-8-0 cuda-npp-dev-8-0 cuda-nvgraph-8-0 cuda-nvgraph-dev-8-0 cuda-nvml-dev-8-0  
  12.   cuda-nvrtc-8-0 cuda-nvrtc-dev-8-0 cuda-samples-8-0 cuda-toolkit-8-0  
  13.   cuda-visual-tools-8-0 dh-apparmor fonts-dejavu g++-4.8 g++-4.8-multilib  
  14.   gir1.2-gconf-2.0 gir1.2-gnomebluetooth-1.0 gstreamer1.0-clutter iproute  
  15.   lib32stdc++-4.8-dev libatk-wrapper-java libatk-wrapper-java-jni libavcodec54  
  16.   libavformat54 libavutil52 libboost-atomic1.54.0 libboost-chrono1.54.0  
  17.   libboost-context1.54.0 libboost-date-time1.54.0 libboost-filesystem1.54.0  
  18.   libboost-graph1.54.0 libboost-iostreams1.54.0 libboost-locale1.54.0  
  19.   libboost-log1.54.0 libboost-math1.54.0 libboost-program-options1.54.0  
  20.   libboost-python1.54.0 libboost-random1.54.0 libboost-regex1.54.0  
  21.   libboost-serialization1.54.0 libboost-signals1.54.0 libboost-system1.54.0  
  22.   libboost-test1.54.0 libboost-thread1.54.0 libboost-timer1.54.0 libboost-wave1.54.0  
  23.   libc-ares2 libcamel-1.2-45 libclutter-gst-2.0-0 libcolord1 libcolorhug1 libcr0  
  24.   libcwidget3 libdbi1 libebackend-1.2-7 libebook-1.2-14 libebook-contacts-1.2-0  
  25.   libedata-book-1.2-20 libedataserver-1.2-18 libegl1-mesa-drivers libelfg0 libept1.4.12  
  26.   libgcrypt11-dev libgdata13 libgee2 libgif4 libgnome-bluetooth11 libgnome-desktop-3-7  
  27.   libgnutlsxx27 libgphoto2-port10 libgtop2-7 libicu52 libilmbase6 libimobiledevice4  
  28.   libisl10 libjavascriptcoregtk-3.0-0 libllvm3.4 libmbim-glib0 libmysqlclient-dev  
  29.   libmysqlclient18 libopenexr6 libopenjpeg2 libopenvg1-mesa libpango1.0-0 libpci-dev  
  30.   libplist1 libpoppler44 libqmi-glib0 libqpdf13 libqt5positioning5 libqt5sensors5  
  31.   libqt5test5 librrd4 libservlet3.0-java libsigc++-2.0-0c2a libsqlite3-dev libswscale2  
  32.   libsystemd-journal0 libtorque2 libupower-glib1 libusbmuxd2 libv8-3.14.5 libvpx1  
  33.   libvte-2.90-9 libvte-2.90-common libwebkitgtk-3.0-0 libwebkitgtk-3.0-common  
  34.   libx264-142 libx32stdc++-4.8-dev libxcb-util0 libxen-4.4 libzeitgeist-1.0-1  
  35.   linux-image-3.13.0-145-generic linux-image-extra-3.13.0-145-generic  
  36.   linux-image-generic-lts-xenial linux-lts-xenial-cloud-tools-4.4.0-31  
  37.   linux-lts-xenial-tools-4.4.0-31 nvidia-prime obex-data-server php5-cli php5-common  
  38.   php5-json php5-readline python-colorama python-cups python-dbus-dev python-distlib  
  39.   python-gnomekeyring python-gobject python-html5lib python-notify python-pycurl  
  40.   python-smbc python-urlgrabber python-xapian python3-colorama python3-distlib  
  41.   python3-imaging ttf-dejavu ttf-dejavu-core ttf-dejavu-extra watershed  
  42. Use 'sudo apt autoremove' to remove them.  
  43. The following packages will be REMOVED:  
  44.   cuda* cuda-8-0* cuda-demo-suite-8-0* cuda-drivers* cuda-runtime-8-0* libcuda1-384*  
  45.   libcupti5.5* nvidia-384* nvidia-384-dev* nvidia-modprobe* nvidia-opencl-icd-384*  
  46.   nvidia-settings*  
  47. 0 upgraded, 0 newly installed, 12 to remove and 56 not upgraded.  
  48. After this operation, 375 MB disk space will be freed.  
  49. Do you want to continue? [Y/n] y  
  50. (Reading database ... 219065 files and directories currently installed.)  
  51. Removing cuda (8.0.61-1) ...  
  52. Removing cuda-8-0 (8.0.61-1) ...  
  53. Removing cuda-demo-suite-8-0 (8.0.61-1) ...  
  54. Removing cuda-runtime-8-0 (8.0.61-1) ...  
  55. Removing cuda-drivers (384.111-1) ...  
  56. Removing libcupti5.5:amd64 (5.5.22-3ubuntu1) ...  
  57. Purging configuration files for libcupti5.5:amd64 (5.5.22-3ubuntu1) ...  
  58. Removing libcuda1-384 (384.111-0ubuntu1) ...  
  59. Purging configuration files for libcuda1-384 (384.111-0ubuntu1) ...  
  60. Removing nvidia-opencl-icd-384 (384.111-0ubuntu1) ...  
  61. Purging configuration files for nvidia-opencl-icd-384 (384.111-0ubuntu1) ...  
  62. Removing nvidia-384-dev (384.111-0ubuntu1) ...  
  63. Removing nvidia-384 (384.111-0ubuntu1) ...  
  64. Removing all DKMS Modules  
  65. Done.  
  66. update-alternatives: using /usr/lib/nvidia-384-prime/ld.so.conf to provide /etc/ld.so.con  
  67. f.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in auto modeupdate-alternatives: using /usr/lib/nvidia-384-prime/ld.so.conf to provide /etc/ld.so.con  
  68. f.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in auto modeupdate-alternatives: using /usr/lib/nvidia-384-prime/alt_ld.so.conf to provide /etc/ld.so  
  69. .conf.d/i386-linux-gnu_GL.conf (i386-linux-gnu_gl_conf) in auto modeupdate-alternatives: using /usr/lib/nvidia-384-prime/alt_ld.so.conf to provide /etc/ld.so  
  70. .conf.d/i386-linux-gnu_EGL.conf (i386-linux-gnu_egl_conf) in auto modeupdate-alternatives: using /usr/lib/x86_64-linux-gnu/mesa/ld.so.conf to provide /etc/ld.s  
  71. o.conf.d/x86_64-linux-gnu_GL.conf (x86_64-linux-gnu_gl_conf) in auto modeupdate-alternatives: using /usr/lib/x86_64-linux-gnu/mesa-egl/ld.so.conf to provide /etc/  
  72. ld.so.conf.d/x86_64-linux-gnu_EGL.conf (x86_64-linux-gnu_egl_conf) in auto modeupdate-initramfs: deferring update (trigger activated)  
  73. Purging configuration files for nvidia-384 (384.111-0ubuntu1) ...  
  74. update-initramfs: deferring update (trigger activated)  
  75. Removing nvidia-modprobe (384.111-0ubuntu1) ...  
  76. Removing nvidia-settings (384.111-0ubuntu1) ...  
  77. Purging configuration files for nvidia-settings (384.111-0ubuntu1) ...  
  78. Processing triggers for libc-bin (2.23-0ubuntu10) ...  
  79. Processing triggers for man-db (2.7.5-1) ...  
  80. Processing triggers for initramfs-tools (0.122ubuntu8.11) ...  
  81. update-initramfs: Generating /boot/initrd.img-4.4.0-124-generic  
  82. W: Possible missing firmware /lib/firmware/ast_dp501_fw.bin for module ast  
  83. Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...  
  84. Processing triggers for mime-support (3.59ubuntu1) ...  
  85. Processing triggers for gnome-menus (3.13.3-6ubuntu3.1) ...  


13. 继续安装cuda

安装细节:


[plain] view plain copy
  1. Installing the NVIDIA display driver...  
  2. Installing the CUDA Toolkit in /usr/local/cuda-9.1 ...  
  3. Installing the CUDA Samples in /home/linlf/tools/cuda9.1 ...  
  4. Copying samples to /home/linlf/tools/cuda9.1/NVIDIA_CUDA-9.1_Samples now...  
  5. Finished copying samples.  
  6.   
  7. ===========  
  8. = Summary =  
  9. ===========  
  10.   
  11. Driver:   Installed  
  12. Toolkit:  Installed in /usr/local/cuda-9.1  
  13. Samples:  Installed in /home/linlf/tools/cuda9.1  
  14.   
  15. Please make sure that  
  16.  -   PATH includes /usr/local/cuda-9.1/bin  
  17.  -   LD_LIBRARY_PATH includes /usr/local/cuda-9.1/lib64, or, add /usr/local/cuda-9.1/lib64 to /etc/ld.so.conf and run ldconfig as root  
  18.   
  19. To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.1/bin  
  20. To uninstall the NVIDIA Driver, run nvidia-uninstall  
  21.   
  22. Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.1/doc/pdf for detailed information on setting up CUDA.  
  23.   
  24. Logfile is /tmp/cuda_install_31995.log  


14 最后,如果想更改cuda版本成9.1:

[html] view plain copy
  1. rm –rf /usr/local/cuda  
  2.   
  3. ln -s /usr/local/cuda-9.1 /usr/local/cuda  

参考: https://blog.csdn.net/u010821666/article/details/79957071
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要在Ubuntu 16.04上安装CUDA 9.0,必须按照以下步骤进行操作: 1. 首先,从NVIDIA官方网站上下载CUDA 9.0的安装包(通常是一个.run文件)。确保下载的文件和操作系统的位数匹配(32位或64位)。 2. 在终端中导航到下载的安装包所在的目录,并确保安装包有执行权限。若无执行权限,可以使用以下命令添加执行权限: ```bash chmod +x 文件名.run ``` 3. 关闭所有正在运行的图形用户界面。可以通过使用以下命令进行: ```bash sudo service lightdm stop ``` 4. 执行安装脚本以启动安装程序: ```bash sudo ./文件名.run ``` 5. 按照安装程序的提示进行操作。在“Installation Option”选项卡中,选择安装CUDA Toolkit并确保选择与操作系统和硬件兼容的驱动程序版本。 6. 在安装期间,可能会提示你安装NVIDIA驱动程序。如果系统尚未安装适当的驱动程序,则可以选择是以便一同安装驱动程序。 7. 安装完成后,打开终端并将CUDA库和二进制文件的路径添加到环境变量中。可以使用以下命令创建一个新的文件并编辑它: ```bash sudo nano /etc/environment ``` 8. 将以下两行添加到文件的末尾(根据安装路径更改): ``` PATH="/usr/local/cuda-9.0/bin:$PATH" LD_LIBRARY_PATH="/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH" ``` 9. 保存并退出文本编辑器,并重新启动系统。 10. 系统重启后,可以通过运行以下命令来验证安装是否成功: ```bash nvcc --version ``` 如果安装成功,将会显示CUDA的版本号。 希望以上步骤可以帮助你在Ubuntu 16.04上成功安装CUDA 9.0。 ### 回答2: 首先,您需要确保您的计算机满足CUDA 9.0的系统要求。您需要一张支持CUDANVIDIA显卡和安装了Ubuntu 16.04的操作系统。 以下是在Ubuntu 16.04上安装CUDA 9.0的步骤: 1. 首先,下载CUDA 9.0的安装包。可以从NVIDIA的官方网站上下载对应版本的CUDA安装包。 2. 下载完成后,打开终端并切换到CUDA安装包所在的目录。例如,使用以下命令切换到Downloads目录: ``` cd ~/Downloads ``` 3. 接下来,运行以下命令解压CUDA安装包: ``` tar -xvzf cuda_9.0.176_384.81_linux.run ``` 4. 解压完成后,切换到解压后的目录: ``` cd cuda-linux* ``` 5. 运行安装脚本。您可以使用以下命令进行安装: ``` sudo ./cuda-linux*.run ``` 在安装过程中,您需要接受相关许可协议和选择要安装的组件。根据您的需要进行选择并按照提示操作。 6. 安装完成后,您需要配置环境变量。可以使用以下命令打开.bashrc文件: ``` nano ~/.bashrc ``` 在文件末尾添加以下两行代码: ``` export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ``` 保存并关闭文件。 7. 最后,刷新环境变量并确认CUDA安装成功。使用以下命令刷新环境变量: ``` source ~/.bashrc ``` 然后,运行以下命令验证CUDA是否安装成功: ``` nvcc --version ``` 如果安装成功,您将看到CUDA的版本号。 这就是在Ubuntu 16.04上安装CUDA 9.0的步骤。请按照以上步骤进行操作,并确保您满足系统要求。希望对您有所帮助! ### 回答3: 要在Ubuntu 16.04上安装CUDA 9.0,您需要按照以下步骤进行操作: 1. 下载CUDA 9.0安装包:在NVIDIA的官方网站上下载适合您操作系统的CUDA 9.0安装包。 2. 关闭图形界面:在开始安装CUDA之前,您需要先关闭图形界面。按下Ctrl + Alt + F1切换到命令行界面。 3. 卸载旧版本的NVIDIA驱动程序(如果有):如果您之前已经安装了NVIDIA驱动程序,可以通过运行以下命令来卸载它: ``` sudo apt-get remove --purge nvidia* ``` 4. 安装CUDA 9.0:在命令行界面中,导航到您下载的CUDA 9.0安装包所在的目录,并运行以下命令来进行安装: ``` chmod +x cuda_9.0_*.run sudo ./cuda_9.0_*.run ``` 5. 配置环境变量:安装完成后,需要将CUDA的路径添加到系统环境变量中。编辑`~/.bashrc`文件,并在文件末尾添加以下行: ``` export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ``` 6. 更新环境变量:保存文件后,运行以下命令以更新环境变量: ``` source ~/.bashrc ``` 至此,您已成功在Ubuntu 16.04上安装了CUDA 9.0。您可以通过运行以下命令来验证安装是否成功: ``` nvcc --version ``` 希望这些步骤能帮助您顺利完成CUDA 9.0的安装。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值