WSL快速配置编译环境+ZSH

  1. 在Microsoft Store中安装Ubuntu(为方便升级系统故不安装带版本号的Ubuntu)。控制面板\程序\程序和功能->启用或关闭Windows功能,勾选“适用于Linux的Windows子系统”。以管理员身份运行PowerShell执行
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

    重启计算机。

  2. 对于WSL1,其根目录位于C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs。根据清华大学开源软件镜像站Ubuntu 镜像使用帮助修改/etc/apt/sources.list,注意选择你的ubuntu版本为相应版本(如20.04 LTS)。
  3. 执行
    sudo apt-get update
    sudo apt-get upgrade

    更新。

  4. 执行

    sudo apt-get install cmake gcc clang gdb build-essential

    安装C++编译环境。

  5. 执行

    wget https://raw.githubusercontent.com/JetBrains/clion-wsl/master/ubuntu_setup_env.sh && bash ubuntu_setup_env.sh

    配置CLion。

    ssh username@localhost -p2222

    设置SSH连接。参考https://www.jetbrains.com/help/clion/how-to-use-wsl-development-environment-in-clion.html#wsl-general

  6. WSL已预装vim、git、wget、curl、python3、perl等。执行

    sudo apt install nodejs npm

    安装node.js:
    The following NEW packages will be installed:
      binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9
      gcc-9-base gyp javascript-common libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5
      libatomic1 libauthen-sasl-perl libbinutils libc-ares2 libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0
      libctf0 libdata-dump-perl libdpkg-perl libencode-locale-perl libfakeroot libfile-basedir-perl
      libfile-desktopentry-perl libfile-fcntllock-perl libfile-listing-perl libfile-mimeinfo-perl libfont-afm-perl
      libgcc-9-dev libgomp1 libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl
      libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl
      libhttp-negotiate-perl libio-html-perl libio-socket-ssl-perl libio-stringy-perl libipc-system-simple-perl libisl22
      libitm1 libjs-inherits libjs-is-typedarray libjs-psl libjs-typedarray-to-buffer liblsan0 liblwp-mediatypes-perl
      liblwp-protocol-https-perl libmailtools-perl libmpc3 libnet-dbus-perl libnet-http-perl libnet-smtp-ssl-perl
      libnet-ssleay-perl libnode-dev libnode64 libpython2-stdlib libpython2.7-minimal libpython2.7-stdlib libquadmath0
      libssl-dev libstdc++-9-dev libtie-ixhash-perl libtimedate-perl libtry-tiny-perl libtsan0 libubsan1 liburi-perl
      libuv1-dev libwww-perl libwww-robotrules-perl libx11-protocol-perl libxcursor1 libxml-parser-perl libxml-twig-perl
      libxml-xpathengine-perl linux-libc-dev make manpages-dev node-abbrev node-ajv node-ansi node-ansi-align
      node-ansi-regex node-ansi-styles node-ansistyles node-aproba node-archy node-are-we-there-yet node-asap node-asn1
      node-assert-plus node-asynckit node-aws-sign2 node-aws4 node-balanced-match node-bcrypt-pbkdf node-bl node-bluebird
      node-boxen node-brace-expansion node-builtin-modules node-builtins node-cacache node-call-limit node-camelcase
      node-caseless node-chalk node-chownr node-ci-info node-cli-boxes node-cliui node-clone node-co node-color-convert
      node-color-name node-colors node-columnify node-combined-stream node-concat-map node-concat-stream node-config-chain
      node-configstore node-console-control-strings node-copy-concurrently node-core-util-is node-cross-spawn
      node-crypto-random-string node-cyclist node-dashdash node-debug node-decamelize node-decompress-response
      node-deep-extend node-defaults node-define-properties node-delayed-stream node-delegates node-detect-indent
      node-detect-newline node-dot-prop node-duplexer3 node-duplexify node-ecc-jsbn node-editor node-encoding
      node-end-of-stream node-err-code node-errno node-es6-promise node-escape-string-regexp node-execa node-extend
      node-extsprintf node-fast-deep-equal node-find-up node-flush-write-stream node-forever-agent node-form-data
      node-from2 node-fs-vacuum node-fs-write-stream-atomic node-fs.realpath node-function-bind node-gauge node-genfun
      node-get-caller-file node-get-stream node-getpass node-glob node-got node-graceful-fs node-gyp node-har-schema
      node-har-validator node-has-flag node-has-symbol-support-x node-has-to-string-tag-x node-has-unicode
      node-hosted-git-info node-http-signature node-iconv-lite node-iferr node-import-lazy node-imurmurhash node-inflight
      node-inherits node-ini node-invert-kv node-ip node-ip-regex node-is-npm node-is-obj node-is-object
      node-is-path-inside node-is-plain-obj node-is-retry-allowed node-is-stream node-is-typedarray node-isarray
      node-isexe node-isstream node-isurl node-jsbn node-json-parse-better-errors node-json-schema
      node-json-schema-traverse node-json-stable-stringify node-json-stringify-safe node-jsonify node-jsonparse
      node-jsonstream node-jsprim node-latest-version node-lazy-property node-lcid node-libnpx node-locate-path
      node-lockfile node-lodash node-lodash-packages node-lowercase-keys node-lru-cache node-make-dir node-mem node-mime
      node-mime-types node-mimic-fn node-mimic-response node-minimatch node-minimist node-mississippi node-mkdirp
      node-move-concurrently node-ms node-mute-stream node-nopt node-normalize-package-data node-npm-bundled
      node-npm-package-arg node-npm-run-path node-npmlog node-number-is-nan node-oauth-sign node-object-assign node-once
      node-opener node-os-locale node-os-tmpdir node-osenv node-p-cancelable node-p-finally node-p-is-promise node-p-limit
      node-p-locate node-p-timeout node-package-json node-parallel-transform node-path-exists node-path-is-absolute
      node-path-is-inside node-performance-now node-pify node-prepend-http node-process-nextick-args node-promise-inflight
      node-promise-retry node-promzard node-proto-list node-prr node-pseudomap node-psl node-pump node-pumpify
      node-punycode node-qs node-qw node-rc node-read node-read-package-json node-readable-stream node-registry-auth-token
      node-registry-url node-request node-require-directory node-require-main-filename node-resolve node-resolve-from
      node-retry node-rimraf node-run-queue node-safe-buffer node-semver node-semver-diff node-set-blocking node-sha
      node-shebang-command node-shebang-regex node-signal-exit node-slash node-slide node-sorted-object node-spdx-correct
      node-spdx-exceptions node-spdx-expression-parse node-spdx-license-ids node-sshpk node-ssri node-stream-each
      node-stream-iterate node-stream-shift node-strict-uri-encode node-string-decoder node-string-width node-strip-ansi
      node-strip-eof node-strip-json-comments node-supports-color node-tar node-term-size node-text-table node-through
      node-through2 node-timed-out node-tough-cookie node-tunnel-agent node-tweetnacl node-typedarray
      node-typedarray-to-buffer node-uid-number node-unique-filename node-unique-string node-unpipe node-uri-js
      node-url-parse-lax node-url-to-options node-util-deprecate node-uuid node-validate-npm-package-license
      node-validate-npm-package-name node-verror node-wcwidth.js node-which node-which-module node-wide-align
      node-widest-line node-wrap-ansi node-wrappy node-write-file-atomic node-xdg-basedir node-xtend node-y18n
      node-yallist node-yargs node-yargs-parser nodejs nodejs-doc npm perl-openssl-defaults python-pkg-resources python2
      python2-minimal python2.7 python2.7-minimal x11-xserver-utils xdg-utils
    0 upgraded, 382 newly installed, 0 to remove and 23 not upgraded.
    Need to get 59.1 MB of archives.
    After this operation, 267 MB of additional disk space will be used.
    使用npm config set命令

    npm config set registry https://registry.npm.taobao.org
    npm config set cache="/mnt/d/Program_Files/node_cache"
    npm config set prefix="/mnt/d/Program_Files/npm/node_modules"

    设置registry、cache和prefix。此时metrics-registry = "https://registry.npm.taobao.org/"。使用

    npm install -g npm

    更新npm。

  7. 执行

    sudo apt install golang

    安装golang:
    The following NEW packages will be installed:
      binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 g++ g++-9 gcc gcc-9 gcc-9-base golang golang-1.13
      golang-1.13-doc golang-1.13-go golang-1.13-race-detector-runtime golang-1.13-src golang-doc golang-go
      golang-race-detector-runtime golang-src libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev
      libctf-nobfd0 libctf0 libdpkg-perl libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libmpc3
      libquadmath0 libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev manpages-dev pkg-config
    0 upgraded, 44 newly installed, 0 to remove and 23 not upgraded.
    Need to get 102 MB of archives.
    After this operation, 501 MB of additional disk space will be used.

  8. 执行

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

    安装Rust。

  9. 执行

    sudo apt install zsh

    安装ZSH。然后根据https://ohmyz.sh/安装oh-my-zsh。

  10. 配置.zshrc:

    export ZSH="/home/ayka_tsuzuki/.oh-my-zsh"
    export PATH=$HOME/bin:/usr/local/bin:$PATH
    export PATH=$HOME/.local/bin:/usr/local/bin:$PATH
    export RUSTUP_IO_THREADS=1
    ZSH_THEME="agnoster_wsl"
    ZSH_DISABLE_COMPFIX="true
    plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
    source $ZSH/oh-my-zsh.sh
    . "/home/ayka_tsuzuki/.local/share/lscolors.sh"
    DEFAULT_USER="ayka_tsuzuki"
    eval `dircolors ~/dircolors.256dark
    export http_proxy=http://127.0.0.1:11000
    export https_proxy=http://127.0.0.1:11000
    export ftp_proxy=http://127.0.0.1:11000
    # eval "$(starship init zsh)"
    SSH_ENV="$HOME/.ssh/environment"
    function start_agent {
            echo "Initialising new SSH agent..."
            /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
            echo succeeded
            chmod 600 "${SSH_ENV}"
            . "${SSH_ENV}" > /dev/null
            /usr/bin/ssh-add;
    }
    if [ -f "${SSH_ENV}" ]; then
            . "${SSH_ENV}" > /dev/null
            ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
            start_agent;
            }
    else
            start_agent;
    fi
    trap 'test -n "$SSH_AGENT_PID" && eval `/usr/bin/ssh-agent -k`' 0

    其中安装插件zsh-autosuggestions步骤参考https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md:在$ZSH_CUSTOM/plugins(默认为~/.oh-my-zsh/custom/plugins)目录下执行

    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    安装插件zsh-syntax-highlighting步骤参考https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md:在$ZSH_CUSTOM/plugins(默认为~/.oh-my-zsh/custom/plugins)目录下执行

    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    安装Starship参考WSL Ubuntu使用Cargo安装Starship
    使用自定义主题:

    cp ~/.oh-my-zsh/theme/agnoster.zsh-theme ~/.oh-my-zsh/custom/theme/agnoster_wsl.zsh-theme
    vim ~/.oh-my-zsh/custom/theme/agnoster_wsl.zsh-theme

    prompt_dir() {
      prompt_segment blue $CURRENT_FG '%~'
    }
    blue改为0.75。参考WSL 使用 oh-my-zsh 让终端更美 Edwinpanzzz
  11. (可选)Windows Terminal配置:settings.json中的"profiles"下的"list"下添加

    {
        "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
        "name": "Ubuntu",
        "source": "Windows.Terminal.Wsl"
    }

    (可选)Fluent Terminal设置:配置文件->新建。名称:WSL;可执行程序位置:C:\windows\system32\wsl.exe;环境变量:TERM xterm-256color。该设置为默认设置。
    (可选)ConEmu配置:参考GitHub ConEmu/ConEmu.github.io库Issue #45 Failed to run WSL on ConEmu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ayka

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值