wsl安装配置vscode(亲测有用)
文章目錄
- 具體安裝過程
- 參考
筆者的環境:win10家庭版,已安裝wsl ubuntu
具體安裝過程
第一步:打開官方文檔:開始通過適用于 Linux 的 Windows 子系統使用 Visual Studio Code(https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/wsl-vscode)
依次完成下圖所示的兩項安裝:在windows下安裝vscode(記得選擇添加到path),安裝遠程開發擴展包。
完成以上安裝以后,筆者是按照這篇博文https://blog.csdn.net/reeeeein/article/details/104628415/來進行操作的。
第一步:打開linux,默認源切換到阿里云。
sudo sed -i s@/archive.ubuntu.com/@/mirrors.aliyun.com/@g /etc/apt/sources.list sudo apt update -y sudo apt upgrade -y第二步之一:下載vscode
sudo apt-add-repository -r ppa:ubuntu-desktop/ubuntu-make sudo apt update注:這里是筆者對原文的優化,原文為
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
但是會報錯,因而使用筆者上方提供的即可。
第二步之二:切換到root用戶
然后執行下面代碼安裝vscode,(這里需要切換到root模式,使用命令su,再輸入root密碼,然后執行下面代碼安裝vscode)
第三步:配置和運行vscode
執行成功后,需要切換到普通用戶,輸入命令exit即可完成切換。
然后輸入以下命令:
成功后,然后要在wsl里安裝g++和gdb:
sudo apt-get install gdb sudo apt-get install g++第四步:配置cpp環境
在自己的文件夾下面創建一個文件.vscode,添加以下四個json文件,用于保存配置信息。
c_cpp_properties.json
{"configurations": [{"name": "Linux","includePath": [],"defines": ["_DEBUG","_UNICODE"],"compilerPath": "/usr/bin/g++","intelliSenseMode": "${default}"}],"version": 4 }launch.json
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "g++ build and debug active file","type": "cppdbg","request": "launch","program": "${fileDirname}/${fileBasenameNoExtension}","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "g++ build active file","miDebuggerPath": "/usr/bin/gdb"}] }settings.json
{"files.associations": {"iostream": "cpp"} }task.json
{"tasks": [{"type": "shell","label": "g++ build active file","command": "/usr/bin/g++","args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}"],"options": {"cwd": "/usr/bin"}}],"version": "2.0.0" }第五步:創建cpp文件編譯運行
具體編譯過程:按F5,選擇C++(GDB/LLDB)
或者直接使用命令行編譯,筆者是使用終端進行編譯運行如下
參考
[1]https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/wsl-vscode
[2]https://blog.csdn.net/reeeeein/article/details/104628415/
[3]https://stackoverflow.com/questions/60249177/e-the-repository-http-ppa-launchpad-net-certbot-certbot-ubuntu-focal-release
[4]wsl遇到問題The repository ‘http://ppa.launchpad.net/ubuntu-desktop/ubuntu-make/ubuntu focal Release‘解決方法
總結
以上是生活随笔為你收集整理的wsl安装配置vscode(亲测有用)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wsl遇到问题The repositor
- 下一篇: github遇到问题Updates we