• Ubuntu下安装Scala


    前言

    弄了一下终于成功装上了,这里对此进行一下总结

    安装虚拟机

    VMware虚拟机安装Ubuntu(超详细图文教程)_vmware安装ubuntu-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_43374681/article/details/129248167Download Ubuntu Desktop | Download | Ubuntuicon-default.png?t=N7T8https://ubuntu.com/download/desktop安装redhat虚拟机_怎么安装redhat的虚拟机-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_64066303/article/details/130287039?spm=1001.2014.3001.5501有了前面安装红帽的经验,我相信Ubuntu的安装是得心应手了。

    安装Java

    Ubuntu下安装Java_ubuntu安装java-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/JqlScala/article/details/133462691直接可以指令安装

    更新所有软件包

    sudo apt update
    

     安装默认Java运行时环境(JRE)

     sudo apt install default-jre
    

     安装Java开发工具包(JDK)

     sudo apt install default-jdk
    

     验证是否安装成功

    1. root@feng-virtual-machine:~# java -version
    2. openjdk version "11.0.22" 2024-01-16
    3. OpenJDK Runtime Environment (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1)
    4. OpenJDK 64-Bit Server VM (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1, mixed mode, sharing)

    安装Scala

    All Available Versions | The Scala Programming Language (scala-lang.org)icon-default.png?t=N7T8https://www.scala-lang.org/download/all.html(Spark)学习进度十五(虚拟机(ubuntu)安装scala和使用) - 细胞何 - 博客园 (cnblogs.com)icon-default.png?t=N7T8https://www.cnblogs.com/hwh000/p/12310651.html

     然后按照他的步骤,解压和配置环境。

    添加(/usr/local/scala是自己的安装路径)

    1. export SCALA_HOME=/usr/local/scala
    2. export PATH=${SCALA_HOME}/bin:$PATH

     使环境变量生效

    source /etc/profile
    1. root@feng-virtual-machine:~# scala -version
    2. Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL

    但是结果出现了

    1. root@feng-virtual-machine:/usr/local/scala# ./bin/scala
    2. Exception in thread "main" java.lang.NoClassDefFoundError: javax/script/Compilable
    3. at scala.tools.nsc.interpreter.ILoop.createInterpreter(ILoop.scala:118)
    4. at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:911)
    5. at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
    6. at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
    7. at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
    8. at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
    9. at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:74)

    ./bin/scala出错(Exception in thread “main“java. lang . NoClassDefFoundError: javax/script/Compilable)_exception in thread "main" java.lang.noclassdeffou-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_52350007/article/details/120569898推测是版本不兼容的问题,然后我找到了一个选择版本的

    JDK Compatibility | Scala Documentation (scala-lang.org)icon-default.png?t=N7T8https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html

     因为JDK显示是11,之后我安装了2.11.12版本的Scala还是失败了,然后安装3.0.0的没有明显的下载文件,只有一个GitHub的地址。

    所以我选择下载2.13.0的版本。

    按照同样的方法结果又可以了。

    1. root@feng-virtual-machine:/usr/local/scala/bin# scala
    2. Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 11.0.22).
    3. Type in expressions for evaluation. Or try :help.
    4. scala> println("Hello World!")
    5. Hello World!
    6. scala>

    虽然是出现了一个警告,但是还是可以运行。

    1. root@feng-virtual-machine:~# cd /usr/local/scala
    2. root@feng-virtual-machine:/usr/local/scala# sudo mkdir mycode
    3. root@feng-virtual-machine:/usr/local/scala# cd ./mycode
    4. root@feng-virtual-machine:/usr/local/scala/mycode# ls
    5. root@feng-virtual-machine:/usr/local/scala/mycode# sudo vim HelloWorld.scala
    6. root@feng-virtual-machine:/usr/local/scala/mycode# ls
    7. HelloWorld.scala
    8. root@feng-virtual-machine:/usr/local/scala/mycode# scalac HelloWorld.scala
    9. warning: there was one deprecation warning (since 2.13.0); re-run with -deprecation for details
    10. one warning found
    11. root@feng-virtual-machine:/usr/local/scala/mycode# ls
    12. 'HelloWorld$.class' HelloWorld.class HelloWorld.scala
    13. root@feng-virtual-machine:/usr/local/scala/mycode# scala -classpath . HelloWorld
    14. Hello World!
    15. root@feng-virtual-machine:/usr/local/scala/mycode# ls
    16. 'HelloWorld$.class' HelloWorld.class HelloWorld.scala
    17. root@feng-virtual-machine:/usr/local/scala/mycode# cat HelloWorld.scala
    18. object HelloWorld{
    19. def main(args: Array[String]){
    20. println("Hello World!")
    21. }
    22. }
    23. root@feng-virtual-machine:/usr/local/scala/mycode#

     按要求加上deprecation参数,显示该语法被弃用了。

    1. root@feng-virtual-machine:/usr/local/scala/mycode# scalac -deprecation HelloWorld.scala
    2. HelloWorld.scala:3: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `main`'s return type
    3. def main(args: Array[String]){
    4. ^
    5. one warning found

     按照要求修改之后就可以了,添加` :Unit=`

    1. root@feng-virtual-machine:/usr/local/scala/mycode# scalac HelloWorld.scala
    2. root@feng-virtual-machine:/usr/local/scala/mycode# cat HelloWorld.scala
    3. object HelloWorld{
    4. def main(args: Array[String]): Unit={
    5. println("Hello World!")
    6. }
    7. }
    8. root@feng-virtual-machine:/usr/local/scala/mycode# ls
    9. 'HelloWorld$.class' HelloWorld.class HelloWorld.scala
    10. root@feng-virtual-machine:/usr/local/scala/mycode# scala -classpath . HelloWorld
    11. Hello World!
    12. root@feng-virtual-machine:/usr/local/scala/mycode#

    FinalShell

    FinalShell官网 (hostbuf.com)icon-default.png?t=N7T8https://www.hostbuf.com/这里还有一个软件,感兴趣的小伙伴可以尝试一下,在windows系统下连接Linux的虚拟机。

    其中“名称”是自己起,“主机”是用ifconfig指令查看,“端口”默认是22,认证是root,密码就是root的密码。密码不知道可以设置一下。

    【ubuntu】设置root用户密码_ubuntu设置root用户密码-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_43500200/article/details/131118075我的是inet 192.168.92.130

    1. root@feng-virtual-machine:~# ifconfig
    2. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    3. inet 192.168.92.130 netmask 255.255.255.0 broadcast 192.168.92.255
    4. inet6 fe80::5c97:a5d8:e86f:ce76 prefixlen 64 scopeid 0x20
    5. ether 00:0c:29:5f:3c:62 txqueuelen 1000 (以太网)
    6. RX packets 279948 bytes 161217845 (161.2 MB)
    7. RX errors 42 dropped 42 overruns 0 frame 0
    8. TX packets 385434 bytes 102925217 (102.9 MB)
    9. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
    10. device interrupt 19 base 0x2000
    11. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    12. inet 127.0.0.1 netmask 255.0.0.0
    13. inet6 ::1 prefixlen 128 scopeid 0x10
    14. loop txqueuelen 1000 (本地环回)
    15. RX packets 7077 bytes 854481 (854.4 KB)
    16. RX errors 0 dropped 0 overruns 0 frame 0
    17. TX packets 7077 bytes 854481 (854.4 KB)
    18. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

     当然输入密码的时候,密码不会回显。

    1. root@feng-virtual-machine:~# sudo passwd root
    2. 新的密码:
    3. 重新输入新的密码:
    4. passwd:已成功更新密码
    5. root@feng-virtual-machine:~#

    补:

     决定还是安装新版的Scala,JDK还是17,Scala选择了3.3.3.

    Java Downloads | Oracleicon-default.png?t=N7T8https://www.oracle.com/java/technologies/downloads/#java17

    # sudo dpkg -i jdk-17_linux-x64_bin.deb
    1. # java -version
    2. java version "17.0.10" 2024-01-16 LTS
    3. Java(TM) SE Runtime Environment (build 17.0.10+11-LTS-240)
    4. Java HotSpot(TM) 64-Bit Server VM (build 17.0.10+11-LTS-240, mixed mode, sharing)
    5. root@feng-virtual-machine:~#

     然后使用了Scala,结果报错了。

    1. scala> println("hello world")
    2. java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI
    3. at java.base/jdk.internal.jrtfs.JrtPath.toUri(JrtPath.java:175)
    4. at scala.tools.nsc.classpath.JrtClassPath.asURLs(DirectoryClassPath.scala:216)
    5. at scala.tools.nsc.classpath.AggregateClassPath.$anonfun$asURLs$1(AggregateClassPath.scala:63)
    6. at scala.collection.StrictOptimizedIterableOps.flatMap(StrictOptimizedIterableOps.scala:118)
    7. at scala.collection.StrictOptimizedIterableOps.flatMap$(StrictOptimizedIterableOps.scala:105)
    8. at scala.collection.immutable.Vector.flatMap(Vector.scala:113)
    9. at scala.tools.nsc.classpath.AggregateClassPath.asURLs(AggregateClassPath.scala:63)
    10. at scala.tools.nsc.interpreter.IMain.compilerClasspath(IMain.scala:93)
    11. at scala.tools.nsc.interpreter.IMain.makeClassLoader(IMain.scala:352)
    12. at scala.tools.nsc.interpreter.IMain.ensureClassLoader(IMain.scala:275)
    13. at scala.tools.nsc.interpreter.IMain.classLoader(IMain.scala:278)
    14. at scala.tools.nsc.interpreter.IMain.runtimeMirror$lzycompute(IMain.scala:168)
    15. at scala.tools.nsc.interpreter.IMain.runtimeMirror(IMain.scala:168)
    16. at scala.tools.nsc.interpreter.IMain.$anonfun$getModuleIfDefined$1(IMain.scala:177)
    17. at scala.tools.nsc.interpreter.IMain.getModuleIfDefined(IMain.scala:170)
    18. at scala.tools.nsc.interpreter.IMain.readRootPath(IMain.scala:289)
    19. at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.resolvePathToSymbol(IMain.scala:662)
    20. at scala.tools.nsc.interpreter.IMain$Request.resultSymbol$lzycompute(IMain.scala:919)
    21. at scala.tools.nsc.interpreter.IMain$Request.resultSymbol(IMain.scala:918)
    22. at scala.tools.nsc.interpreter.IMain$Request.typeOf$lzycompute(IMain.scala:930)
    23. at scala.tools.nsc.interpreter.IMain$Request.typeOf(IMain.scala:935)
    24. at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:897)
    25. at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:493)
    26. at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:487)
    27. at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:470)
    28. at scala.tools.nsc.interpreter.shell.ILoop.interpretStartingWith(ILoop.scala:930)
    29. at scala.tools.nsc.interpreter.shell.ILoop.command(ILoop.scala:787)
    30. at scala.tools.nsc.interpreter.shell.ILoop.processLine(ILoop.scala:462)
    31. at scala.tools.nsc.interpreter.shell.ILoop.loop(ILoop.scala:485)
    32. at scala.tools.nsc.interpreter.shell.ILoop.run(ILoop.scala:1019)
    33. at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:87)
    34. at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:91)
    35. at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:102)
    36. at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:107)
    37. at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
    38. Caused by: java.lang.RuntimeException: /packages cannot be represented as URI
    39. ... 35 more
    40. That entry seems to have slain the compiler. Shall I replay
    41. your session? I can re-run each line except the last one.
    42. [y/n]

    于是按照前面的要求下载的3.3.3版本的Scala。

    Release 3.3.3 · lampepfl/dotty (github.com)icon-default.png?t=N7T8https://github.com/lampepfl/dotty/releases/tag/3.3.3

    # sudo tar -zxvf scala3-3.3.3.tar.gz -C /usr/local
    1. # scala -version
    2. Scala code runner version 3.3.3 -- Copyright 2002-2024, LAMP/EPFL
    1. scala> println("hello world")
    2. hello world

  • 相关阅读:
    互联网名词解释
    网络的笔记
    YOLOv7改进策略:一种新颖的可扩张残差(DWR)注意力模块,增强多尺度感受野特征,助力小目标检测
    controller接收List入参
    RTI-DDS代码分析使用介绍
    Ubuntu 缩减磁盘空间
    SECS/GEM半导体协议介绍
    开始使用 ELEMENTOR
    项目踩坑—跨域问题
    微信小程序游戏开发│石头剪刀布游戏(附源码)
  • 原文地址:https://blog.csdn.net/weixin_64066303/article/details/136414462