Windows Terminal 开发环境

Terminal

Windows 终端安装 | Microsoft Learn

cmder

Cmder | Console Emulator

Cmder 的优点:

  • 是免安装压缩包,解压直接可用
  • 支持 Git 等命令
  • 支持多标签页
  • 支持自定义终端
  • 内置多种主题,支持自定义主题
shell 复制代码
Generating Clink initial settings in "D:\workspace\tool\cmder\config\clink_settings"
已复制         1 个文件。
Additional *.lua files in "D:\workspace\tool\cmder\config" are loaded on startup.
Creating Cmder prompt config file: "D:\workspace\tool\cmder\config\cmder_prompt_config.lua"
已复制         1 个文件。
Creating initial user_aliases store in "D:\workspace\tool\cmder\config\user_aliases.cmd"...
已复制         1 个文件。
Running Git for Windows one time Post Install....
"running post-install"
'C:\WINDOWS\system32\drivers\etc\hosts' -> '/etc/hosts'
'C:\WINDOWS\system32\drivers\etc\protocol' -> '/etc/protocols'
'C:\WINDOWS\system32\drivers\etc\services' -> '/etc/services'
'C:\WINDOWS\system32\drivers\etc\networks' -> '/etc/networks'
找不到批处理文件。
Creating user startup file: "D:\workspace\tool\cmder\config\user_profile.cmd"
已复制         1 个文件。

D:\workspace\tool\cmder

Windowws 安装包管理 scoop

再谈谈 Scoop 这个 Windows 下的软件包管理器 - Chawye Hsu

介绍

Scoop是一款适用于Windows平台的命令行软件(包)管理工具,这里是Github介绍页。简单来说,就是可以通过命令行工具(PowerShell、CMD等)实现软件(包)的安装管理等需求,通过简单的一行代码实现软件的下载、安装、卸载、更新等操作 。其灵感来源于macOS的Homebrew,Mac用户可以去了解了解。

当然如果用过Linux系统,使用apt-get工具安装过软件,或者用过Python,知道pip工具用于管理Python各种依赖包,那么理解Scoop就比较容易,这些工具的设计理念与使用方法都非常类似。

Scoop一般用来管理绿色软件,即是一种通过解压压缩包即可就地使用的软件,对于比较专业软件(比如Office、Adobe等)支持不好(虽然有大神在自制这样的第三方仓库,不过好像一直没实现)。

安装

根据官方的条件要求,你需要:

  1. Windows 7 SP1+或Windows Server 2008+(当然你用主流的Windows 10或Windows 11更没有什么问题)。
  2. [PowerShell 5](及以上,包含[PowerShell Core])和[.NET Framework 4.5](及以上)(当然我相信读者朋友们肯定都满足了,实在未满足可通过文本链接前去下载)。

还有两个中国用户需要确认的额外的条件(当然我觉得你能看到这篇文章自然也都满足了):

  1. 由于众所周知的天朝网络原因,你需要能够正常访问Github并下载其资源。
  2. 由于环境变量中文路径的支持问题,你的Windows用户名或自定义的安装路径不得包含中文。

设置PowerShell权限

为了让PowerShell可以执行脚本,首先需要设置PowerShell执行策略,通过输入以下命令Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser即可。(如果之前已开启,可忽略。)

安装Scoop

如果你需要更改默认的安装目录,则需要在执行以上命令前添加环境变量的定义,通过执行以下命令完成:

ruby 复制代码
$env:SCOOP='D:\Applications\Scoop'
[Environment]::SetEnvironmentVariable('SCOOP', $env:SCOOP, 'User')

其中目录D:\Applications\Scoop可根据自己的情况修改。

通过以下命令,可以将Scoop安装到默认目录(C:\Users<username>\scoop):

vbnet 复制代码
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

或者另一条更短的命令:

arduino 复制代码
iwr -useb get.scoop.sh | iex

完成之后,相应位置就会生成一个scoop文件夹,如图所示:

简单解释下子目录中其他文件夹的含义:

  • apps------所有通过scoop安装的软件都在里面。
  • buckets------管理软件的仓库,用于记录哪些软件可以安装、更新等信息,默认添加main仓库,主要包含无需GUI的软件,可手动添加其他仓库或自建仓库,具体在推荐软件仓库中介绍。
  • cache------软件下载后安装包暂存目录。
  • persit------用于储存一些用户数据,不会随软件更新而替换。
  • shims------用于软链接应用,使应用之间不会互相干扰,实际使用过程中无用户操作不必细究。
shell 复制代码
 ~/scoop/buckets/main (master)
λ git remote show -n origin
* remote origin
  Fetch URL: https://github.com/ScoopInstaller/Main.git
  Push  URL: https://github.com/ScoopInstaller/Main.git
  HEAD branch: (not queried)
  Remote branches: (status not queried)
    fix-test
    master
    source_of_manifests
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push' (status not queried):
    (matching) pushes to (matching)
λ git remote set-url origin https://gitee.com/scoop-bucket/main.git

Scoop常用命令

Scoop的操作命令十分简单,基本结构是scoop + 动词 + 对象,动词就是一个操作动作,如安装、卸载,对象一般就是软件名了(支持通配符*操作),当然这需要你先打开命令行工具。比如我想安装typora,通过输入scoop install typora即可自动完成软件的官网进入+下载+安装等操作。

以下是一些常用的命令说明:

  • search------搜索仓库中是否有相应软件。
  • install------安装软件。
  • uninstall------卸载软件。
  • update------更新软件。可通过scoop update *更新所有已安装软件,或通过scoop update更新所有软件仓库资料及Scoop自身而不更新软件。
  • hold------锁定软件阻止其更新。
  • info------查询软件简要信息。
  • home------打开浏览器进入软件官网。

如果你访问Github有问题,或下载其中的资源有问题,可尝试以下方法: scoop: 国内镜像版 (gitee.com)

  1. 使用Gitee镜像源。可能备份更新得不是那么勤快,以及实际下载软件包同样会有网络问题,所以不推荐。在命令行中输入scoop config SCOOP_REPO https://gitee.com/squallliu/scoop修改仓库源的地址。

WSL 安装

旧版 WSL 的手动安装步骤 | Microsoft Learn

步骤 1 - 启用适用于 Linux 的 Windows 子系统

需要先启用"适用于 Linux 的 Windows 子系统"可选功能,然后才能在 Windows 上安装 Linux 分发。

以管理员身份打开 PowerShell("开始"菜单 >"PowerShell" >单击右键 >"以管理员身份运行"),然后输入以下命令:

bash 复制代码
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

步骤 2 - 启用虚拟机功能

安装 WSL 2 之前,必须启用"虚拟机平台"可选功能。 计算机需要虚拟化功能才能使用此功能。

以管理员身份打开 PowerShell 并运行:

bash 复制代码
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

重新启动计算机,以完成 WSL 安装并更新到 WSL 2。

步骤 3 - 下载 Linux 内核更新包

Linux 内核更新包会安装最新版本的 WSL 2 Linux 内核,以便在 Windows 操作系统映像中运行 WSL。 (若要运行 Microsoft Store 中的 WSL 并更频繁地推送更新,请使用 wsl.exe --installwsl.exe --update。)

  1. 下载最新包:

如果使用的是 ARM64 计算机,请下载 ARM64 包。 如果不确定自己计算机的类型,请打开命令提示符或 PowerShell,并输入:systeminfo | find "系统类型"Caveat: 在英文版 Windows 上,你可能必须修改搜索文本"System Type"字符串

  1. 运行上一步中下载的更新包。 (双击以运行 - 系统将提示你提供提升的权限,选择"是"以批准此安装。)

步骤 4 - 将 WSL 2 设置为默认版本

打开 PowerShell,然后在安装新的 Linux 发行版时运行以下命令,将 WSL 2 设置为默认版本:

arduino 复制代码
wsl --set-default-version 2

步骤 5 - 下载发行版

在某些情况下,你可能无法(或不想)使用 Microsoft Store 安装 WSL Linux 发行版。 你可能正在运行不支持 Microsoft Store 的 Windows Server 或长期服务 (LTSC) 桌面操作系统 SKU,或者你的公司网络策略和/或管理员不允许在你的环境中使用 Microsoft Store。 在这些情况下,虽然 WSL 本身可用,但你可能需要直接下载 Linux 发行版。 如果 Microsoft Store 应用不可用,可使用以下链接来下载并手动安装 Linux 发行版:

如果愿意,你也可通过命令行下载首选的发行版,可将 PowerShell 与 Invoke-WebRequest cmdlet 一起使用。 例如,下载 Ubuntu 20.04:

dart 复制代码
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu.appx -UseBasicParsing

如果下载需要很长时间,请通过设置 $ProgressPreference = 'SilentlyContinue' 来关闭进度栏

你还可以选择使用 curl 命令行实用程序来下载。 使用 curl 下载 Ubuntu 20.04:

arduino 复制代码
curl.exe -L -o ubuntu-2004.appx https://aka.ms/wslubuntu2004

错误排查: docs.microsoft.com/zh-c

使用

  • Windows 访问 WSL 目录
shell 复制代码
explorer.exe .
  • WSL 访问 Windows 目录, /mnt 目录下挂载了 C, D 等分区
shell 复制代码
@LAPTOP-BJ2UPLHA:~$ ls /mnt/
c  d  wsl
  • 查看已经安装 linux 版本
shell 复制代码
λ wsl -l --all -v
  NAME      STATE           VERSION
* Ubuntu    Running         2
  • 终止正在运行的wsl
shell 复制代码
wsl --shutdown
  • 将需要迁移的Linux,进行导出
shell 复制代码
wsl --export Ubuntu D:/export.tar
  • 导出完成之后,就需要将原有的分发进行卸载
shell 复制代码
wsl --unregister Ubuntu
  • 将导出的文件放到需要保存的地方,进行导入即可
shell 复制代码
wsl --import Ubuntu D:\export\ D:\export.tar --version 2

WSL 开发环境

更换配置源

切换源,可能导致安装包版本依赖不匹配,尽量不要切换源

安装好了第一步之后当然是换源啦,因为大部分 linux 发行版的服务器都在国外所以下载速度都会很慢,使用国内的镜像下载速度就快很多,肯定比没换舒爽多了

  1. 将系统源文件复制一份备用
shell 复制代码
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  1. 用 vi 编辑器打开源文件
shell 复制代码
sudo vi /etc/apt/sources.list

然后直接输入49dd,就可以清除所有内容了,然后输入i就可以进行编辑了

  1. 找到国内源复制粘贴 其他系统该页面也有,每个系统的操作都是大同小异,话不多说开 lu 它,进去之后了也是要选择跟系统版本相符合的源 Ubuntu 20.04换国内源 清华源 阿里源 中科大源 163源 - 知乎 (zhihu.com)
shell 复制代码
# 默认注释了源码镜像以提高 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
arduino 复制代码
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
  1. 更新系统
sql 复制代码
sudo apt-get -y update && sudo apt-get -y upgrade

Q&A

Q: 更换源后:apt-get update 报错,可能是系统世时间设置异常,可以使用 date 查看时间,然后修正时间

shell 复制代码
$ sudo apt-get -y update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease [114 kB]
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease [108 kB]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease [114 kB]
Reading package lists... Done
E: Release file for https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-updates/InRelease is not valid yet (invalid for another 4h 56min 15s). Updates for this repository will not be applied.
E: Release file for https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-backports/InRelease is not valid yet (invalid for another 4h 58min 7s). Updates for this repository will not be applied.
E: Release file for https://mirrors.tuna.tsinghua.edu.cn/ubuntu/dists/focal-security/InRelease is not valid yet (invalid for another 4h 54min 44s). Updates for this repository will not be applied.

A: 修正时间的方法。

WSL hwclock 设置系统时间

shell 复制代码
# WSL 系统时钟与 Windows 保持一致
~$ sudo hwclock -s
leoliang@LAPTOP-BJ2UPLHA:~$ date
Sat Aug  5 10:07:21 CST 2023
shell 复制代码
# 交互式时区配置界面
sudo apt install tzdata
sudo dpkg-reconfigure tzdata

Ubuntu

  • 方法一:使用timedatectl命令
    • 列出可用时区:命令timedatectl将显示当前时区设置以及其他相关信息。记下您要更改的时区的ID。
    • 修改时区:输入以下命令来更改时区,将"YOUR_TIMEZONE"替换为您要设置的时区ID: sudo timedatectl set-timezone YOUR_TIMEZONE

例如,如果您要将时区设置为"Asia/Shanghai",则命令将如下所示: sudo timedatectl set-timezone Asia/Shanghai

  • 方法二:修改/etc/timezone文件
    • 使用文本编辑器打开/etc/timezone文件:在终端中输入以下命令,使用您喜欢的文本编辑器打开/etc/timezone文件: sudo vim /etc/timezone 。在打开的文件中,将当前时区替换为您想要设置的新时区。例如,如果您要将时区设置为"Asia/Shanghai",则在文件中将显示: Asia/Shanghai

更新系统时间:输入以下命令来更新系统时间以反映新的时区设置: sudo systemctl restart systemd-timesyncd

编译环境

  • cmake
shell 复制代码
sudo apt install cmake
  • c++ 编译环境
shell 复制代码
sudo apt install build-essential

下面的报错,因为切换了其他 apt 源,导致版本依赖无法解决

shell 复制代码
$ sudo apt install build-essential
[sudo] password for leoliang:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 dpkg-dev : Depends: bzip2 but it is not installable
 g++-9 : Depends: gcc-9-base (= 9.4.0-1ubuntu1~20.04.1) but 9.4.0-1ubuntu1~20.04.2 is to be installed
         Depends: gcc-9 (= 9.4.0-1ubuntu1~20.04.1) but 9.4.0-1ubuntu1~20.04.2 is to be installed
         Depends: libstdc++-9-dev (= 9.4.0-1ubuntu1~20.04.1) but it is not going to be installed
 libc6-dev : Depends: libc6 (= 2.31-0ubuntu9.9) but 2.35-0ubuntu3.1 is to be installed
             Depends: libc-dev-bin (= 2.31-0ubuntu9.9) but it is not going to be installed
             Depends: libcrypt-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

SSH

  • Windows 安装 OpenSSH 安装 OpenSSH | Microsoft Learn

  • ubuntu 安装 ssh-server 输入:sudo ps -e |grep ssh-->回车-->有sshd,说明ssh服务已经启动,如果没有启动,输入sudo service ssh start-->回车-->ssh服务就会启动

    输出如下:

ruby 复制代码
username@ubuntu:~$ sudo ps -e |grep ssh
   2068 ?        00:00:00 ssh-agent
   4068 ?        00:00:00 sshd

ssh-agent表示ssh-client启动,sshd表示ssh-server启动了。

如果缺少sshd,说明ssh服务没有启动或者没有安装。

安装ssh-client命令:sudo apt-get install openssh-client

安装ssh-server命令:sudo apt-get install openssh-server

ssh服务默认的端口是22,可以更改端口,使用如下命令打开ssh配置文件:
sudo gedit /etc/ssh/sshd_config

配置文件内容如下:

ini 复制代码
# Package generated configuration file   
# See the sshd(8) manpage for details   
# What ports, IPs and protocols we listen for  
Port 22
# Package generated configuration file
# See the sshd(8) manpage for details
# What ports, IPs and protocols we listen for

修改端口号(Port)后,重启ssh服务即可生效,命令如下:
sudo /etc/init.d/ssh restart

  • SSH 在 Linux 系统上是非常常用的工具,通过 SSH Client 我们可以连接到运行了 SSH Server 的远程机器上。SSH Client 的基本使用方法是: SSH 基本用法 - 知乎 (zhihu.com)
shell 复制代码
ssh user@remote -p port
@user 是你在远程机器上的用户名,如果不指定的话默认为当前用户
@remote 是远程机器的地址,可以是 IP,域名,或者是后面会提到的别名
@port 是 SSH Server 监听的端口,如果不指定的话就为默认值 22

实际上,知道了上面这三个参数,用任意的 SSH Client 都能连接上 SSH Server,例如在 Windows 上 PuTTY 就是很常用的 SSH Client。

sql 复制代码
local$ ssh user@remote -p port            
user@remote's password:

在执行了 ssh 命令之后,远程机器会询问你的密码。在输入密码的时候,屏幕上不会显示明文密码,也不会显示 ******,这样别人就不会看到你的密码长度了,按下回车即可登入。

登入之后,你就可以操作远程机器啦!

相关推荐
shuxianshrng8 分钟前
大气网格化精细化监管监测系统
大数据·服务器·windows·经验分享
晚睡早起₍˄·͈༝·͈˄*₎◞ ̑̑30 分钟前
苍穹外卖学习笔记(七)
java·windows·笔记·学习·mybatis
偷偷小野猪3 小时前
想要自动删除浏览器历史记录吗?这样设置就对了
windows·edge浏览器
充值内卷8 小时前
WPF入门教学四 WPF控件概述
windows·ui·wpf
程序猿小D21 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
iummature1 天前
ZLMediaKit Windows编译以及使用
windows
周伯通*1 天前
Windows上,使用远程桌面连接Ubuntu
linux·windows·ubuntu
GDAL1 天前
GNU力量注入Windows:打造高效跨平台开发新纪元
服务器·windows·gnu
小徐敲java1 天前
Windows本地制作java证书(与jeecgboot配置本地证书ssl问题)
java·windows·ssl
春蕾夏荷_7282977251 天前
electron nsis打包windows应用程序
javascript·windows·electron·nsis