How to create virtual environment with pyenv-virtualenv plugin

pyenv-virtualenv is a pyenv plugin that provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.

If you don't have pyenv in your system, follow below post;

Installing pyenv-virtualenv

$ brew update
$ brew install pyenv-virtualenv

Setting PATH

Run one of the following commands in terms of your shell's .rc file.

$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc

Creating virtual environment

$ mkdir python_demo
$ cd python_demo
$ pyenv install 3.11.4
$ pyenv virtualenv 3.11.4 python_demo-3.11.4
$ pyenv virtualenvs
$ pyenv prefix python_demo-3.11.4
/Users/kenanhancer/.pyenv/versions/python_demo-3.11.4
$ ls -Llat $(pyenv prefix python_demo-3.11.4)

drwxr-xr-x  14 kenanhancer  staff  448 19 Jun 17:36 bin
-rw-r--r--   1 kenanhancer  staff  107 19 Jun 17:36 pyvenv.cfg
drwxr-xr-x   3 kenanhancer  staff   96 19 Jun 17:36 lib
drwxr-xr-x   2 kenanhancer  staff   64 19 Jun 17:36 include
$ tree -a -L 4 $(pyenv prefix python_demo-3.11.4)

├── bin
│   ├── Activate.ps1
│   ├── activate
│   ├── activate.csh
│   ├── activate.fish
│   ├── pip
│   ├── pip3
│   ├── pip3.11
│   ├── pydoc
│   ├── python -> python3.11
│   ├── python3 -> python3.11
│   └── python3.11 -> /Users/kenanhancer/.pyenv/versions/3.11.4/bin/python3.11
├── include
│   └── python3.11
├── lib
│   └── python3.11
│       └── site-packages
│           ├── _distutils_hack
│           ├── distutils-precedence.pth
│           ├── pip
│           ├── pip-23.1.2.dist-info
│           ├── pkg_resources
│           ├── setuptools
│           └── setuptools-65.5.0.dist-info
└── pyvenv.cfg
Continue reading

How to install Java with Jabba

Runtime version managers make developers life easier. So, I tested different Java version managers. But, Jabba is the easiest one for me.

You can read previously posted How to install java articles.

Java Specification Versions:

Here are the major releases:

  1. Java 1.0 (January 1996) – The original version.
  2. Java 1.1 (February 1997) – Introduced several significant features, including the JavaBeans API.
  3. Java 2 (J2SE 1.2) (December 1998) – Introduced the Swing application framework.
  4. J2SE 1.3 (May 2000) – Introduced the HotSpot JVM.
  5. J2SE 1.4 (February 2002) – Introduced regular expressions, image I/O API, and more.
  6. Java SE 5 (J2SE 1.5) (September 2004) – Introduced generics, metadata annotations, enumerated types, and more.
  7. Java SE 6 (December 2006) – Introduced scripting support, JVM improvements, and more.
  8. Java SE 7 (July 2011) – Introduced the try-with-resources statement, the diamond operator, and more.
  9. Java SE 8 (March 2014) – Introduced lambdas, streams, and the java.time package.
  10. Java SE 9 (September 2017) – Introduced the module system.
  11. Java SE 10 (March 2018) – Introduced local-variable type inference (var).
  12. Java SE 11 (September 2018) – Introduced String::lines, isBlank, and other methods, plus the java.net.http HttpClient.
  13. Java SE 12 (March 2019) – Introduced switch expressions (preview) and more.
  14. Java SE 13 (September 2019) – Introduced text blocks (preview) and more enhancements.
  15. Java SE 14 (March 2020) – Introduced pattern matching for instanceof (preview) and other improvements.
  16. Java SE 15 (September 2020) – Continued the introduction and enhancement of several features.
  17. Java SE 16 (March 2021) – Introduced sealed classes (preview) and other enhancements.
  18. Java SE 17 (September 2021) – This version is an LTS (Long Term Support) release, which means it will receive updates for a longer period than the interim releases.
  19. Java SE 18 (March 2022)
  20. Java SE 19 (September 2022)
  21. Java SE 20 (March 2023)
  22. Java SE 21 (September 2023)

Java has moved to a time-driven release model, with new versions being released every six months. Not all of these are long-term support (LTS) versions. As of Java 17, the LTS versions have been Java 8, Java 11, and Java 17.

Installing or Upgrading Jabba

For more details in Jabba

$ curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | bash && . ~/.jabba/jabba.sh

Usage

# list available JDK's
$ jabba ls-remote

# you can use any valid semver range to narrow down the list
$ jabba ls-remote zulu@~1.8.60
$ jabba ls-remote "*@>=1.6.45 <1.9" --latest=minor

# install Oracle JDK
$ jabba install 1.8

# install Oracle Server JRE
$ jabba install sjre@1.8

# install Adopt OpenJDK (Hotspot)
$ jabba install adopt@1.8-0

# install Adopt OpenJDK (Eclipse OpenJ9)
$ jabba install adopt-openj9@1.9-0

# install Zulu OpenJDK
$ jabba install zulu@1.8
$ jabba install zulu@~1.8.144 # same as "zulu@>=1.8.144 <1.9"

# install IBM SDK, Java Technology Edition
$ jabba install ibm@1.8

# install GraalVM CE
$ jabba install graalvm@1.0-0

# install OpenJDK
$ jabba install openjdk@1.10-0

# install OpenJDK with Shenandoah GC
$ jabba install openjdk-shenandoah@1.10-0

# install from custom URL
# (supported qualifiers: zip (since 0.3.0), tgz, tgx (since 0.10.0), dmg, bin, exe)
$ jabba install 1.8.0-custom=tgz+http://example.com/distribution.tar.gz
$ jabba install 1.8.0-custom=tgx+http://example.com/distribution.tar.xz
$ jabba install 1.8.0-custom=zip+file:///opt/distribution.zip

# uninstall JDK
$ jabba uninstall zulu@1.6.77

# link system JDK
$ jabba link system@1.8.72 /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk

# list all installed JDK's
$ jabba ls

# switch to a different version of JDK (it must be already `install`ed)
$ jabba use adopt@1.8
$ jabba use zulu@~1.6.97

$ echo "1.8" > .jabbarc
# switch to the JDK specified in .jabbarc (since 0.5.0)
$ jabba use

# set default java version on shell (since 0.2.0)
# this version will automatically be "jabba use"d every time you open up a new terminal
$ jabba alias default 1.8
Continue reading

How to install Java with brew and jenv

jenv is a tool that helps you switch between different java versions in your development machine. But, Jenv doesn't install Java for you.

Use your platform appropriate package manager to install Java. On macOS, brew is recommended.

Install Java with Homebrew

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my blog below.

I also posted how to install Java JDK manually in the following post.

Actually I already mentioned how to install Java JDK in the above post, but I will shortly show one more time

$ brew tap adoptopenjdk/openjdk
$ brew search jdk

==> Formulae
openjdk                                                                              openjdk@11

==> Casks
adoptopenjdk
adoptopenjdk12
adoptopenjdk13-openj9
adoptopenjdk14-openj9-jre-large
adoptopenjdk9
adoptopenjdk10
adoptopenjdk12-jre
adoptopenjdk13-openj9-jre
adoptopenjdk14-openj9-large
jdk-mission-control
adoptopenjdk11
adoptopenjdk12-openj9
adoptopenjdk13-openj9-jre-large
adoptopenjdk8
oracle-jdk
adoptopenjdk11-jre
adoptopenjdk12-openj9-jre
adoptopenjdk13-openj9-large
adoptopenjdk8-jre
oracle-jdk-javadoc
adoptopenjdk11-openj9
adoptopenjdk12-openj9-jre-large
adoptopenjdk14
adoptopenjdk8-openj9
sapmachine-jdk
adoptopenjdk11-openj9-jre
adoptopenjdk12-openj9-large
adoptopenjdk14-jre
adoptopenjdk8-openj9-jre
adoptopenjdk11-openj9-jre-large
adoptopenjdk13
adoptopenjdk14-openj9
adoptopenjdk8-openj9-jre-large
adoptopenjdk11-openj9-large
adoptopenjdk13-jre
adoptopenjdk14-openj9-jre
adoptopenjdk8-openj9-large
$ brew cask install adoptopenjdk
$ java --version

openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)
Continue reading

How to install Ansible with brew or pip

You can install Ansible quickly in your system with Homebrew( or PIP(Package manager for Python)

Install Ansible with Homebrew

If you are using macOS, then you can use Homebrew.

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit previous post below.

Run the following commands in your terminal without $ sign.

$ brew update
$ brew install ansible

Checking Ansible version

$ ansible --version

ansible 2.9.7
  config file = None
  configured module search path = ['/Users/kenanhancer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/kenanhancer/.pyenv/versions/3.8.2/lib/python3.8/site-packages/ansible
  executable location = /Users/kenanhancer/.pyenv/versions/3.8.2/bin/ansible
  python version = 3.8.2 (default, May  6 2020, 12:47:50) [Clang 11.0.3 (clang-1103.0.32.59)]

Install Ansible with PIP

Ensure that you have Python and PIP in your system. Check the following page about Python installation.

$ pip install ansible
$ ansible --version

Updating Ansible

$ pip install --upgrade ansible

Installing specific Ansible version

$ pip install ansible==2.2.2.0
$ pip install ansible==2.0.1.0

How to install Python with pyenv version manager

I am using different programming languages like C#, Java, Node.js etc and need to manage runtime versions in my local. So, I like to use runtime version managers.

For example, there are some runtime version managers in Node.js community like nvm or n.

Let's say I work for one Node.js project in dev machine with Node v8.0.0 but other project needs Node v6.0.0

In order to handle, different versions in same machine, we may use runtime version managers.

I just want to find a way to switch between different Python runtime version so that found pyenv runtime version manager.

Pyenv is a simple, powerful and cross-platform tool for managing multiple versions of Python on a single machine. It is very useful when you need to switch between different Python versions for different projects, or when different applications on your system require different Python versions.

So, we can install, uninstall, list or switch between different versions.

Pyenv installation

Click pyenv link for more detailed installation.

Installing pyenv with Homebrew

First, ensure that you have Homebrew installed in your system. Homebrew is a package manager for Mac OS. So if you want to learn more details about it, visit my post.

Run the following commands in your terminal. But, just copy commands without $ sign.

$ brew update
$ brew install pyenv

Setting PATH

Checking shell

output of echo $SHELL can be bash, zsh or fish

$ echo $SHELL

/usr/local/bin/bash

# OR

/bin/zsh

Run the following command for bash, zsh, etc configuration.

$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc

and restart your terminal manually or run the following command to restart automatically.

$ exec "$SHELL"

Upgrading pyenv

$ brew upgrade pyenv

Uninstall pyenv

$ rm -rf $(pyenv root)
$ brew uninstall pyenv

Pyenv commands

List all Python versions installed in system

$ pyenv versions

  system
  3.7.3
* 3.8.2 (set by /Users/kenanhancer/.pyenv/version)

Show current active Python version in system

$ pyenv version

3.8.2 (set by /Users/kenanhancer/.pyenv/version)
Continue reading

How to install Maven

Downloading and Installing Maven

if you want to download Maven manually, download it from http://maven.apache.org/download.cgi

But you can download Maven programmatically as the following. So, run below script in your terminal.

wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

tar -xzvf apache-maven*bin.tar.gz

# Fix the permissions:
# chown -R root:wheel Downloads/apache-maven*

mkdir /usr/local/apache-maven

mv apache-maven* /usr/local/apache-maven

rm apache-maven*

Setting environment variables in zsh

If you are using zsh, then run the following script in your terminal.

nano ~/.zshrc

export M2_HOME=/usr/local/apache-maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

source ~/.zshrc

Setting environment variables in bash

nano ~/.bashrc

# add these three lines at the end of file and CTRL+X and Y and click enter :)

export M2_HOME=/usr/local/apache-maven/apache-maven-3.6.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

source ~/.bashrc

Check Maven Version

# Verify if Maven is running
mvn -version

How to install Kafka

Downloading

wget "https://archive.apache.org/dist/kafka/1.1.0/kafka_2.11-1.1.0.tgz"

tar -xzf kafka_2.11-1.1.0.tgz

Starting Zookeeper and kafka

bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties

Create topic

bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test

List topics

bin/kafka-topics.sh --list --bootstrap-server localhost:9092

or

bin/kafka-topics.sh --list --zookeeper localhost:2181

Send some messages to Kafka

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

or

bin/kafka-console-producer.sh --zookeeper localhost:2181 --topic test

Consume messages from Kafka

bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

How to install Java

Java Specification Versions:

Here are the major releases:

  1. Java 1.0 (January 1996) – The original version.
  2. Java 1.1 (February 1997) – Introduced several significant features, including the JavaBeans API.
  3. Java 2 (J2SE 1.2) (December 1998) – Introduced the Swing application framework.
  4. J2SE 1.3 (May 2000) – Introduced the HotSpot JVM.
  5. J2SE 1.4 (February 2002) – Introduced regular expressions, image I/O API, and more.
  6. Java SE 5 (J2SE 1.5) (September 2004) – Introduced generics, metadata annotations, enumerated types, and more.
  7. Java SE 6 (December 2006) – Introduced scripting support, JVM improvements, and more.
  8. Java SE 7 (July 2011) – Introduced the try-with-resources statement, the diamond operator, and more.
  9. Java SE 8 (March 2014) – Introduced lambdas, streams, and the java.time package.
  10. Java SE 9 (September 2017) – Introduced the module system.
  11. Java SE 10 (March 2018) – Introduced local-variable type inference (var).
  12. Java SE 11 (September 2018) – Introduced String::linesisBlank, and other methods, plus the java.net.http HttpClient.
  13. Java SE 12 (March 2019) – Introduced switch expressions (preview) and more.
  14. Java SE 13 (September 2019) – Introduced text blocks (preview) and more enhancements.
  15. Java SE 14 (March 2020) – Introduced pattern matching for instanceof (preview) and other improvements.
  16. Java SE 15 (September 2020) – Continued the introduction and enhancement of several features.
  17. Java SE 16 (March 2021) – Introduced sealed classes (preview) and other enhancements.
  18. Java SE 17 (September 2021) – This version is an LTS (Long Term Support) release, which means it will receive updates for a longer period than the interim releases.
  19. Java SE 18 (March 2022)
  20. Java SE 19 (September 2022)
  21. Java SE 20 (March 2023)
  22. Java SE 21 (September 2023)

Java has moved to a time-driven release model, with new versions being released every six months. Not all of these are long-term support (LTS) versions. As of Java 17, the LTS versions have been Java 8, Java 11, and Java 17.

Downloading and Installing Java from OpenJDK

if you want to download OpenJDK manually, download it from https://jdk.java.net/

But you can download JDK programmatically as the following. Java SE 7, 8, 9, 10, 11, 12, 13 are included below script. So, run below script in your terminal.

# Java SE 7
wget https://download.java.net/openjdk/jdk7u75/ri/openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz

# Java SE 8
wget https://download.java.net/openjdk/jdk8u40/ri/openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz

# Java SE 9
wget https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz

# Java SE 10
wget https://download.java.net/java/GA/jdk10/10.0.2/19aef61b38124481863b1413dce1855f/13/openjdk-10.0.2_linux-x64_bin.tar.gz

# Java SE 11
wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz

# Java SE 12
wget https://download.java.net/java/GA/jdk12.0.2/e482c34c86bd4bf8b56c0b35558996b9/10/GPL/openjdk-12.0.2_linux-x64_bin.tar.gz

# Java SE 13
wget https://download.java.net/java/GA/jdk13/5b8a42f3905b406298b72d750b6919f6/33/GPL/openjdk-13_linux-x64_bin.tar.gz


mkdir /usr/lib/jvm


# Extract all downloaded jdk files
tar -xvzf openjdk-7u75-b13-linux-x64-18_dec_2014.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-9.0.4_linux-x64_bin.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-10.0.2_linux-x64_bin.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-11.0.2_linux-x64_bin.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-12.0.2_linux-x64_bin.tar.gz -C /usr/lib/jvm

tar -xvzf openjdk-13_linux-x64_bin.tar.gz -C /usr/lib/jvm



# Remove downloaded jdk files
rm openjdk*


# Install Java and Java Compiler to Environment
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-se-7u75-ri/bin/java 1

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-se-7u75-ri/bin/javac 1

update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-se-8u40-ri/bin/java 2

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-se-8u40-ri/bin/javac 2

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-9.0.4/bin/java 3

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-9.0.4/bin/javac 3

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-10.0.2/bin/java 4

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-10.0.2/bin/javac 4

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.2/bin/java 5

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.2/bin/javac 5

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-12.0.2/bin/java 6

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-12.0.2/bin/javac 6

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-13/bin/java 7

update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-13/bin/javac 7



# Verify Java and Java Compiler Installation
# check if java command is pointing to correct path in system
update-alternatives --display java
update-alternatives --display javac

# List all environment variables
update-alternatives --get-selections
# or
update-alternatives --get-selections | grep java
# or
update-alternatives --get-selections | grep ^java

Check Java Version

# Verify if Java is running
java -version

# Verify if Java Compiler is running
javac -version

Homebrew package manager for Mac OS and Linux

Homebrew is a package manager for Mac OS and Linux. You can find more details in http://brew.sh . You can install and uninstall software that you need easily from Command Line Interface(CLI).

There are more than 8500 packages and casks(GUI installation packages) in Homebrew.

Homebrew Cask is the installation and management of GUI macOS applications such as Atom and Google Chrome.

I also posted Chocolatey Package Manager for Windows. Reach out from the following link.

Continue reading