在Linux上安装Racket编程语言

时间:2020-03-21 11:45:45  来源:igfitidea点击:

Racket是基于Lisp的通用多范式编程语言。
Racket专门基于Lisp家族语言Scheme,这使Racket成为Scheme方言。
它也被称为用于创建新编程语言的编程语言。
Racket提供了一个称为DrRacket的图形化IDE,用于使用Racket编程语言开发程序。
Racket是可在Linux,Mac OS和Windows上运行的开放源代码,跨平台的软件。
在本教程中,我们将了解如何在Linux上安装Racket编程语言。

在Linux上安装Racket编程语言

如果我们使用的是Ubuntu及其类似Linux Mint的变体,请使用Racket官方PPA安装Racket。

$sudo add-apt-repository ppa:plt/racket
$sudo apt-get update
$sudo apt-get install racket

在Linux发行版中,从官方下载页面下载最新的Racker安装程序脚本。

$wget https://mirror.racket-lang.org/installers/7.5/racket-7.5-x86_64-linux.sh

转到下载安装程序脚本的位置并使其可执行。
就我而言,安装程序脚本保存在当前目录中。

要使Racket安装程序脚本可执行,只需运行:

$chmod +x racket-7.5-x86_64-linux.sh

最后,如下所示运行Racket安装程序。

$sudo ./racket-7.5-x86_64-linux.sh

我们将被问到几个问题。
请仔细阅读并回答。

第一个问题是我们要使用Unix风格的发行版吗?
我们可以选择是或者否。
如果输入YES,则所有文件将根据Unix约定进入不同的目录。
如果选择“否”,则所有文件都将保存在一个目录中,非常便于将来擦除或者移动。
默认值为“否”。
我建议我们也选择不。
我使用默认值,例如:否。

This program will extract and install Racket v7.5.
Note: the required diskspace for this installation is 525M.
Do you want a Unix-style distribution?
  In this distribution mode files go into different directories according
  to Unix conventions.  A "racket-uninstall" script will be generated
  to be used when you want to remove the installation.  If you say 'no',
  the whole Racket directory is kept in a single installation directory
  (movable and erasable), possibly with external links into it -- this is
  often more convenient, especially if you want to install multiple
  versions or keep it in your home directory.
Enter yes/no (default: no) >no
[...]

第二个问题是我们想其中安装Racket?
如下所示,我们将获得五个选择。
-/usr/racket-这是默认位置。系统范围的安装。如果我们想让系统中的所有用户都使用Racket,那就很好。
-/usr/local/racket-与上面相同(系统范围的安装)。

  • ~/racket(/home/user/racket)-每用户安装。如果我们不是管理员,则可以选择此选项以在$HOME目录本身中安装Racket。
  • ./racket(在当前目录中)。
  • 我们选择的任何自定义位置。

我们所要做的就是输入数字,然后按ENTER键继续。
通常最好在系统范围内安装,让所有用户运行Racket程序。
我使用默认选项,例如:/usr/racket

[...]
Where do you want to install the "racket" directory tree?
  1 - /usr/racket [default]
  2 - /usr/local/racket
  3 - ~/racket (/home/sk/racket)
  4 - ./racket (here)
  Or enter a different "racket" directory to install in.
> 1
[...]

第三个也是最后一个选项是我们要将系统链接放其中:例如球拍,dracket,raco等。
选择一个公共目录(通常是$PATH,例如/usr/local /),因此我们不需要键入可执行文件的完整路径。

[...]
Checking the integrity of the binary archive... ok.
Unpacking into "/usr/racket" (Ctrl+C to abort)...
Done.
If you want to install new system links within the "bin", "man"
  and "share/applications" subdirectories of a common directory prefix
  (for example, "/usr/local") then enter the prefix of an existing
  directory that you want to use.  This might overwrite existing symlinks,
  but not files.
(default: skip links) > /usr/local 
Installing links in "/usr/local/bin"...
  drracket, gracket, gracket-text, mred, mred-text, mzc, mzpp, mzscheme, mztext, pdf-slatex, plt-games, plt-help, plt-r5rs, plt-r6rs, plt-web-server, racket, raco, scribble, setup-plt, slatex, slideshow, swindle
  done.
"/usr/local/share/man/man1" does not exist, skipping.
"/usr/local/share/applications" does not exist, skipping.
Installation complete.

现在已经安装了球拍。

验证racket安装

如果我们已使用PPA安装了Racket,只需键入以下命令即可进入Racket控制台:

$racket

如果我们使用了Racket安装程序脚本并更改了其他安装位置,请在安装过程中回答第二和第三条问题,根据安装位置键入以下任何命令。

$/usr/racket/bin/racket

或者,

$/usr/local/racket/bin/racket

或者,

$~/racket/bin/racket

我使用了PPA,因此我使用以下命令进入了Racket控制台:

$racket

这就是Racket命令提示符在我的Ubuntu 18.04桌面上的样子。

Welcome to Racket v7.5.
>

要阅读Racket文档,请在Racket控制台中输入help,然后按Enter。
这将在默认网络浏览器中打开球拍文档页面。

要退出控制台,请按Ctrl + D。

如果我们不喜欢命令行方式,或者我们是,请使用DrRacket图形IDE。

从Menu或者Dash启动DrRacket。
我们也可以使用以下命令从Terminal启动DrRacket:

$drracket

DrRacket的默认界面如下所示。

在DrRacket界面中键入程序,然后按右上角的“运行”按钮。

这是一个显示给定文本的简单程序:

#lang racket
(displayln "Welcome to theitroad!")

卸载racket

如果我们已使用PPA安装了Racket,只需运行以下命令即可删除Racket:

$sudo apt --purge remove racket

如果我们是使用安装程序手动安装的,则只需删除安装目录即可。
在删除之前,请仔细检查路径。

$sudo rm -r /usr/racket

最后,找到并删除在安装过程中创建的未使用的损坏的符号链接。