Kali-Linux-配置开发环境
阅读原文时间:2023年09月07日阅读:3

本文主要讲解JDK、SDK、eclipse-adt、android studio、cpu模式TensorFlow 的安装配置。update:2019-08-30 03:31:46

JDK

当前系统jdk为openjdk10,导致很多旧版工具无法使用。发现/usr/lib/jvm里面有其他版本。

sudo update-alternatives --config java切换成最低的,保证兼容性。

$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-10-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-10-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-2-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

ORACLE版的JAVA官网把旧版链接给关了,最近意外找到一个java8的下载地址

IBM版的JAVA链接倒是挺全,下载位置在这里

具体上面三个版本差异不作深究,目前保证openjdk8能用即可。

  • JAVA安装步骤

    #解压安装
    $ tar -xzvf jdk.tar.gz $ sudo cp -r jdk1.8 /usr/lib/jvm/
    #配置JAVA
    $ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_191/bin/java" 100
    $ sudo update-alternatives --config java
    There are 4 choices for the alternative java (providing /usr/bin/java).

    Selection Path Priority Status

    0 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1101 auto mode
    1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1101 manual mode

    • 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
      3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
      4 /usr/lib/jvm/jdk1.8.0_191/bin/java 100 manual mode

    Press to keep the current choice[*], or type selection number: 4
    update-alternatives: using /usr/lib/jvm/jdk1.8.0_191/bin/java to provide /usr/bin/java (java) in manual mode
    #配置JAVAC
    $ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_191/bin/javac" 100
    $ sudo update-alternatives --config javac
    There are 3 choices for the alternative javac (providing /usr/bin/javac).

    Selection Path Priority Status

    • 0 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1101 auto mode
      1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1101 manual mode
      2 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode
      3 /usr/lib/jvm/jdk1.8.0_191/bin/javac 100 manual mode

    Press to keep the current choice[*], or type selection number: 3
    update-alternatives: using /usr/lib/jvm/jdk1.8.0_191/bin/javac to provide /usr/bin/javac (javac) in manual mode
    #配置JAR
    $ sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.8.0_191/bin/jar 100
    $ sudo update-alternatives --config jar
    There are 4 choices for the alternative jar (providing /usr/bin/jar).

    Selection Path Priority Status

    0 /usr/lib/jvm/java-10-openjdk-amd64/bin/jar 1101 auto mode
    1 /usr/bin/fastjar 100 manual mode
    2 /usr/lib/jvm/java-10-openjdk-amd64/bin/jar 1101 manual mode
    3 /usr/lib/jvm/java-9-openjdk-amd64/bin/jar 1091 manual mode

    • 4 /usr/lib/jvm/jdk1.8.0_191/bin/jar 100 manual mode

    Press to keep the current choice[*], or type selection number: 4
    #配置JAVA环境变量
    $ export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_191/
    $ export JRE_HOME=/usr/lib/jvm/jdk1.8.0_191/jre
    $ export PATH=$PATH:/usr/lib/jvm/jdk1.8.0_191/bin:/usr/lib/jvm/jdk1.8.0_191/jre/bin
    #验证安装情况
    $ java -version
    java version "1.8.0_191"
    Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

sdk

sudo apt-get install android*

这里有个问题,后面的android studio配置sdk时,普通用户会遇到目录无法写入的情况,不知道通用的办法是如何解决的。采取的临时方案是更改/usr/share/android-sdk目录的所有者权限:

sudo chown -R $(whoami):$(whoami) /usr/share/android-sdk

如有更好的方法,后续于此更新。

  • 手机连接后,adb devices提示:no permissions (udev requires plugdev group membership),解决步骤在这里

eclipse-adt

不要使用apt install 安装,那个版本的一堆问题。从网上下载集成版的,解压使用。

遇到问题:error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory.

解决方案: sudo apt-get install lib32z1

android studio

  1. 下载前先开1antern,这个时候,android-sdk的代理界面要确保清空,以防干扰,终端输入android,配置如图:

  2. https://developer.android.com/studio/下载安装包,然后解压到指定目录

  3. 启动 ~/android-studio/bin/studio.sh , 新建项目,初始化设置

  4. 如果gradle从dl.google.com下载时始终404,在站长之家的ping测试页面找几个ip,添加到/etc/hosts里面。

  5. 接下来等待进度条跑完就可以了,没有喝咖啡的习惯,那就来包泡面先……

    最后,别忘了关灯:ALT+F2、killall lantern,回车。

备用方案:

  • 代理地址:mirrors.neusoft.edu.cn 端口:80

  • 离线下载gradle,不过版本不好控制匹配,不推荐。

TensorFlow cpu模式

apt-get install python-pip python-dev -y
pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

测试下:

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a+b))
42
>>> 

参考

安装:https://medium.com/@firebitsbr/installing-tensorflow-on-kali-rolling-base-cpu-mode-41d05b912155

tf官网:https://www.tensorflow.org/get_started/os_setup#pip_installation

cuda:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

CMake

make命令只是进行了编译,还需要make install来安装

软件安装位置,是由Makefile决定默认安装位置的,一般情况下,都是在/usr/local目录,也可以通过指定prefix=/path/to来决定