前言
弄了一下终于成功装上了,这里对此进行一下总结
安装虚拟机
VMware虚拟机安装Ubuntu(超详细图文教程)_vmware安装ubuntu-CSDN博客https://blog.csdn.net/qq_43374681/article/details/129248167Download Ubuntu Desktop | Download | Ubuntuhttps://ubuntu.com/download/desktop安装redhat虚拟机_怎么安装redhat的虚拟机-CSDN博客https://blog.csdn.net/weixin_64066303/article/details/130287039?spm=1001.2014.3001.5501有了前面安装红帽的经验,我相信Ubuntu的安装是得心应手了。
安装Java
Ubuntu下安装Java_ubuntu安装java-CSDN博客https://blog.csdn.net/JqlScala/article/details/133462691直接可以指令安装
更新所有软件包
sudo apt update
安装默认Java运行时环境(JRE)
sudo apt install default-jre
安装Java开发工具包(JDK)
sudo apt install default-jdk
验证是否安装成功
root@feng-virtual-machine:~# java -version
openjdk version "11.0.22" 2024-01-16
OpenJDK Runtime Environment (build 11.0.22+7-post-Ubuntu-0ubuntu222.04.1)
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)https://www.scala-lang.org/download/all.html(Spark)学习进度十五(虚拟机(ubuntu)安装scala和使用) - 细胞何 - 博客园 (cnblogs.com)https://www.cnblogs.com/hwh000/p/12310651.html
然后按照他的步骤,解压和配置环境。
root@feng-virtual-machine:~# scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
但是结果出现了
root@feng-virtual-machine:/usr/local/scala# ./bin/scala
Exception in thread "main" java.lang.NoClassDefFoundError: javax/script/Compilable
at scala.tools.nsc.interpreter.ILoop.createInterpreter(ILoop.scala:118)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:911)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
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博客https://blog.csdn.net/weixin_52350007/article/details/120569898推测是版本不兼容的问题,然后我找到了一个选择版本的
JDK Compatibility | Scala Documentation (scala-lang.org)https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html
因为JDK显示是11,之后我安装了2.11.12版本的Scala还是失败了,然后安装3.0.0的没有明显的下载文件,只有一个GitHub的地址。
所以我选择下载2.13.0的版本。
按照同样的方法结果又可以了。
root@feng-virtual-machine:/usr/local/scala/bin# scala
Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 11.0.22).
Type in expressions for evaluation. Or try :help.
scala> println("Hello World!")
Hello World!
scala>
虽然是出现了一个警告,但是还是可以运行。
root@feng-virtual-machine:~# cd /usr/local/scala
root@feng-virtual-machine:/usr/local/scala# sudo mkdir mycode
root@feng-virtual-machine:/usr/local/scala# cd ./mycode
root@feng-virtual-machine:/usr/local/scala/mycode# ls
root@feng-virtual-machine:/usr/local/scala/mycode# sudo vim HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# ls
HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# scalac HelloWorld.scala
warning: there was one deprecation warning (since 2.13.0); re-run with -deprecation for details
one warning found
root@feng-virtual-machine:/usr/local/scala/mycode# ls
'HelloWorld$.class' HelloWorld.class HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# scala -classpath . HelloWorld
Hello World!
root@feng-virtual-machine:/usr/local/scala/mycode# ls
'HelloWorld$.class' HelloWorld.class HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# cat HelloWorld.scala
object HelloWorld{
def main(args: Array[String]){
println("Hello World!")
}
}
root@feng-virtual-machine:/usr/local/scala/mycode#
按要求加上deprecation参数,显示该语法被弃用了。
root@feng-virtual-machine:/usr/local/scala/mycode# scalac -deprecation HelloWorld.scala
HelloWorld.scala:3: warning: procedure syntax is deprecated: instead, add `: Unit =` to explicitly declare `main`'s return type
def main(args: Array[String]){
^
one warning found
按照要求修改之后就可以了,添加` :Unit=`
root@feng-virtual-machine:/usr/local/scala/mycode# scalac HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# cat HelloWorld.scala
object HelloWorld{
def main(args: Array[String]): Unit={
println("Hello World!")
}
}
root@feng-virtual-machine:/usr/local/scala/mycode# ls
'HelloWorld$.class' HelloWorld.class HelloWorld.scala
root@feng-virtual-machine:/usr/local/scala/mycode# scala -classpath . HelloWorld
Hello World!
root@feng-virtual-machine:/usr/local/scala/mycode#
FinalShell
FinalShell官网 (hostbuf.com)https://www.hostbuf.com/这里还有一个软件,感兴趣的小伙伴可以尝试一下,在windows系统下连接Linux的虚拟机。
其中“名称”是自己起,“主机”是用ifconfig指令查看,“端口”默认是22,认证是root,密码就是root的密码。密码不知道可以设置一下。
【ubuntu】设置root用户密码_ubuntu设置root用户密码-CSDN博客https://blog.csdn.net/weixin_43500200/article/details/131118075我的是inet 192.168.92.130
root@feng-virtual-machine:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.92.130 netmask 255.255.255.0 broadcast 192.168.92.255
inet6 fe80::5c97:a5d8:e86f:ce76 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5f:3c:62 txqueuelen 1000 (以太网)
RX packets 279948 bytes 161217845 (161.2 MB)
RX errors 42 dropped 42 overruns 0 frame 0
TX packets 385434 bytes 102925217 (102.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 19 base 0x2000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 7077 bytes 854481 (854.4 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7077 bytes 854481 (854.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
当然输入密码的时候,密码不会回显。
root@feng-virtual-machine:~# sudo passwd root
新的密码:
重新输入新的密码:
passwd:已成功更新密码
root@feng-virtual-machine:~#