点击上方蓝字 江湖评谈设为关注/星标
前言
在不为人知的角落里静静发育的BSD家族系统,OpenBSD/NetBSD/FreeBSD/TureOS等等。他们开源深度甚至在某些方面超过了Linux,同为Unix系列,BSD的统一性和更加开放的特征适合作为国产弯道超车的基石。
这些系统也支持.NET这种托管级OOP语言,本篇看下.NET8在FreeBSD上的安装运行。
FreeBSD+.NET8
FreeBSD系统的安装难度略微超越大部分Linux系统,但它的命令的统一性是五花八门眼花缭乱的Linux无法企及的。一般的来说,通过pkg搜索安装包,然后通过pkg安装搜索到的包,即可完整安装一个程序。而不需要APT(用于 Debian 系列),YUM/DNF(用于 RHEL/CentOS 系列),Zypper(用于 openSUSE 系列),以及 Pacman(用于 Arch 系列)。
以.NET为例,比如搜索dotnet可以安装的包:
root@Tyz:~ # pkg search dotnet
dotnet-8.0.6 Open-source developer platform and a cross-platform runtime for cloud, mobile, desktop, and IoT apps
linux-dotnet-cli-2.0.7 Cross-platform .NET implementation
linux-dotnet-runtime-2.0.7 Cross-platform .NET implementation
linux-dotnet-sdk-2.1.201 Cross-platform .NET implementation (Software Development Kit)
linux-dotnet10-runtime-1.0.11 Cross-platform .NET implementation
linux-dotnet10-sdk-1.1.9 Cross-platform .NET implementation (Software Development Kit)
linux-dotnet11-runtime-1.1.8 Cross-platform .NET implementation
php81-pear-Date_Holidays_PHPdotNet-0.1.2 Driver based class to calculate birthdays of members of PHP.net
php82-pear-Date_Holidays_PHPdotNet-0.1.2 Driver based class to calculate birthdays of members of PHP.net
php83-pear-Date_Holidays_PHPdotNet-0.1.2 Driver based class to calculate birthdays of members of PHP.net
php84-pear-Date_Holidays_PHPdotNet-0.1.2 Driver based class to calculate birthdays of members of PHP.net
可以看到当前源里面dotnet-8.0.6可用,然后我们就可以如下安装.NET8了
root@Tyz:~ # pkg install dotnet-8.0.6
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The most recent versions of packages are already installed
FreeBSD提供了Windows/Linux一致的命令,我们看下dotnet版本号:
root:~ # dotnet --info
.NET SDK:
Version: 8.0.106
Commit: ab2d260803
Workload version: 8.0.100-manifests.98636946
environment:
OS Name: FreeBSD
OS Version: 15
OS Platform: FreeBSD
RID: freebsd-x64
Base Path: /usr/local/dotnet/sdk/8.0.106/
新建一个dotnet控制台项目(便于流畅操作,切换了中文版BSD):
root@Tyz:~/dotnet # dotnet new console -n ABC
欢迎使用 .NET 8.0!
---------------------
SDK 版本: 8.0.106
----------------
已安装 ASP.NET Core HTTPS 开发证书。
若要信任该证书,请查看说明: https://aka.ms/dotnet-https-linux
----------------
编写第一个应用: https://aka.ms/dotnet-hello-world
了解新增功能: https://aka.ms/dotnet-whats-new
浏览文档: https://aka.ms/dotnet-docs
报告问题并在 GitHub 上查找来源: https://github.com/dotnet/core
使用 "dotnet --help" 查看可用命令或访问: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
已成功创建模板“控制台应用”。
正在处理创建后操作...
正在还原 /root/dotnet/ABC/ABC.csproj:
Determining projects to restore...
^X Restored /root/dotnet/ABC/ABC.csproj (in 2.63 sec).
已成功还原。
运行下:
root@Tyz:~/dotnet # cd ABC/
root@Tyz:~/dotnet/ABC # ls
ABC.csproj Program.cs obj
root@Tyz:~/dotnet/ABC # dotnet run
Hello, World!
注意了FreeBSD默认编辑器是ee,如果要修改Program.cs可以通过ee来。当然你也可以另外安装vim等其它来修改。
^[ (escape) menu ^y search prompt ^k delete line ^p prev li ^g prev page
^o ascii code ^x search ^l undelete line ^n next li ^v next page
^u end of file ^a begin of line ^w delete word ^b back 1 char
^t top of text ^e end of line ^r restore word ^f forward 1 char
^c command ^d delete char ^j undelete char ^z next word
=====line 2 col 48 lines from top 2 ===========================================
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!!!!!!!!!!!!!!!!!");
和vim不同,ee进去之后不需要切换到插入模式,直接可以修改内容。修改好了之后,摁ESC键,两个aa保存,ab则是不保存退出。
结尾
以上FreeBSD下.NET8的环境安装,比之Linux可能更简单。鉴于FreeBSD可能比之Linux更加开放,可以作为国产基石来发展,肯定比套壳系统的技术硬核太多。
往期精彩回顾
Riscv64-linux用户态
C++20重量级特性:constexpr
关注公众号↑↑↑:江湖评谈