Showing posts with label wsl. Show all posts
Showing posts with label wsl. Show all posts

Tuesday, 20 December 2022

Use sqlcl with Oracle Linux 9 in Windows Terminal on Windows Subsystem for Linux

This post shows a quick and easy way to use Linux commands on Windows in the Windows Terminal by using Windows Subsystem for Linux (WSL). Oracle Developers can - for example - use sqlcl from that environment.

First, install Windows Terminal from the Microsoft Store, or with winget if you have already installed it.

Windows Subsystem for Linux is a great way to have Linux functionality on Windows. For the first time usage, follow the Microsoft Documentation to install it. Oracle Linux 9 is available in the Microsoft Store as fully compatible, free RHEL/CentOS alternatives. That is a nice option, if you have to develop for RHEL, but want to save the license costs. 

And SQLcl can easily installed, as long as you have Java on the system.

Download Oracle Linux 9 from the Microsoft Store or use winget:

winget search 'oracle linux'
winget install 9MXQ65HLMC27

It installed within minutes and can immediately be used. A nice thing about Windows Terminal with WSL is, that WSL automatically registers with Windows Terminal as an option.
If, for whatever reason, the Oracle Linux 9 option does not show up, try the following. Open Windows Terminal settings, choose Add a new profile, select OracleLinux_9 from the select list and click on Duplicate.
Open an Oracle Linux 9 tab and first install all updates via sudo dnf update. 
...

For SQLcl install Java. As this is a minimal installation, unzip and ncurses are missing so also install them.
sudo dnf in java-17-openjdk.x86_64
sudo dnf in ncurses
sudo dnf in unzip.x86_64

Download latest SQLcl zip archive from https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip and unzip it

wget https://download.oracle.com/otn_software/java/sqldeveloper/sqlcl-latest.zip
unzip sqlcl-latest.zip

Add the path to the SQLcl binary to your .bashrc and source it. A cool feature of WLS is, that all your Windows drives are automatically mounted under /mnt/c, /mnt/d etc. So if you already have a network/admin directory under Windows, you can point your TNS_ADMIN to that location. Also set SQLPATH to enable some of the cool features of SQLcl. This is what my .bashrc ends with.

export PATH=/home/oracle/sqlcl/bin:$PATH
export TNS_ADMIN=/mnt/d/Oracle/network/admin
export SQLPATH=~/sql

Create a directory ~/sql and inside a file named login.sql with the above content.

set statusbar on
set highlighting on

 That't it. Open an Oracle Linux 9 tab in your Windows Terminal and connect to all your databases via sqlcl

Or just take it to use all usual Linux commands in Windows.

Wednesday, 20 April 2022

Use SQLcl in Oracle Linux 8 on Windows Subsystem for Linux

There is an update to this post on my Blog.

---8<-----------------------------------------------------------------------------------

Windows Subsystem for Linux is a great way to have Linux functionality on Windows. For the first time usage, follow the Microsoft Documentation to install it. Oracle Linux 7.9 and 8.5 are available in the Microsoft Store as fully compatible, free RHEL/CentOS alternatives. And SQLcl can easily installed, as long as you have Java on the system.

It installed within minutes and can immediately be updated via sudo dnf update. But when I tried so install Java, I got a 

RPM: error: db5 error(-30969) from dbenv->open: BDB0091 DB_VERSION_MISMATCH: Database environment version mismatch

Looks like the RPM repository is defect. I found the solution on GitHub:

sudo -s
cd /var/lib/rpm
rpm --rebuilddb
dd if=/dev/zero of=__db.001 bs=1M count=1
dd if=/dev/zero of=__db.002 bs=1M count=1
dd if=/dev/zero of=__db.003 bs=1M count=1
rpm -qa rpm

Follow the postings on GitHub. There seem to be easier solutions, but I did not double check them, because the first one worked for me.

sudo dnf in java-11-openjdk.x86_64

Now JDK installs without problems, for SQLcl 22.1 at least JDK 11.x is mandatory.

Download latest SQLcl zip archive from oracle.com/sqlcl and copy the contents to any directory, like ~/bin/sqlcl

Add the path to the SQLcl binary to your .bashrc and source it. A cool feature of WLS is, that all your Windows drives are automatically mounted under /mnt/c, /mnt/d etc. So if you already have a network/admin directory under Windows, you can point your TNS_ADMIN to that location. 

export PATH=/home/arne/bin/sqlcl/bin:$PATH
export TNS_ADMIN=/mnt/d/Oracle/network/admin

This is what my .bashrc ends with.

That gives me access from Linux to all databases I have configured under Windows.