Setup Path Environment Variable Freebsd For Composer Java and Go

In FreeBSD environment variables, known as ENV, are dynamic values that have a significant influence on the behavior of running programs and system processes. Environment Variable serves as a means to send important information to software and shapes the way the program interacts with the system environment. Every process in FreeBSD is always associated with a set of environmental variables, which guide its behavior and interactions with other processes.

In the Environment, shell command variables are used as the main channel for interacting with environment variables in an operating system. The shell will act as a command line interpreter, executing instructions entered by the user.

Implementing environment variables on the FreeBSD operating system is very important. With the presence of environment variables, it can be determined where the variables can be accessed or placed, so as to clearly distinguish between global and local scope.

The FreeBSD operating system uses environment variables to store information such as strings and numbers. Variables can be used repeatedly throughout code and you can assign them values, as well as edit them, overwrite them, and delete them.


In this article we will study environment variables on FreeBSD servers. For example, we will use Composer, Go and Java applications.

You can view the environment variables in the FreeBSD operating system by using the env command. This command will display the current values for all environment pairs, name/value and others.

Display environment variable
root@ns3:~ # env
USER=root
LOGNAME=root
HOME=/root
MAIL=/var/mail/root
PATH=/usr/local/.composer/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
TERM=xterm
BLOCKSIZE=K
MM_CHARSET=UTF-8
LANG=C.UTF-8
SHELL=/bin/csh
SSH_CLIENT=192.168.5.54 58432 22
SSH_CONNECTION=192.168.5.54 58432 192.168.5.2 22
SSH_TTY=/dev/pts/0
HOSTTYPE=FreeBSD
VENDOR=amd
OSTYPE=FreeBSD
MACHTYPE=x86_64
SHLVL=1
PWD=/root
GROUP=wheel
HOST=ns3
REMOTEHOST=192.168.5.54
JAVA_VERSION=17.0+
ES_JAVA_HOME=/usr/local/openjdk17
GO_VERSION=1.20+
GOROOT=/usr/local/go120
GOPATH=/usr/local/go120/pkg
COMPOSER_VERSION=2.7+
COMPOSER_HOME=/usr/local/.composer/cache
COMPOSER_MIRROR_PATH_REPOS=/usr/local/.composer
COMPOSER_BINARY=/usr/local/.composer
EDITOR=vi
PAGER=less


1. Java Path Environment Variable

On FreeBSD, the JAVA_HOME and PATH environment variables need to be set to use tools such as javac, java, Tomcat, Solr and others. If you use Java17 or another version, by default, FreeBSD saves the installation process files in /usr/local/openjdk17. The JAVA_HOME environment variable points to the JDK installation directory. To use Java Paths correctly, open the csh.cshrc file, and type the following path script.

/etc/csh.cshrc
root@ns3:~ # ee /etc/csh.cshrc
setenv JAVA_VERSION "17.0+"
setenv ES_JAVA_HOME /usr/local/openjdk17
The above command only creates a temporary Java Path, now we will make permanent Java Path changes by editing the ~/.cshrc file.

~/.cshrc
root@ns3:~ # ee .cshrc
set path = ($ES_JAVA_HOME/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)


2. Go Path Environment Variable

In this section we assume that your FreeBSD has go120 installed. By default, FreeBSD stores all Go installation files in the /usr/local/go120 directory. We will use this directory as a path to store all Go library files from the installation and build process for applications that run with Go.

The steps are almost the same as creating a Java Path. Open the csh.cshrc file, distinguishing only the contents of the script.

/etc/csh.cshrc
root@ns3:~ # ee /etc/csh.cshrc
setenv GO_VERSION "1.20+"
setenv GOROOT /usr/local/go120
setenv GOPATH /usr/local/go120/pkg
Permanently create GOROOT and GOPATH on FreeBSD environment variables.

~/.cshrc
root@ns3:~ # ee .cshrc
set path = ($GOROOT/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
set path = ($GOPATH/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
Let's give an example, the Path Go change. Open the /usr/local/go120/pkg directory, view its contents with the ls -l command.

/etc/csh.cshrc
root@ns3:~ # cd /usr/local/go120/pkg
root@ns3:/usr/local/go120/pkg # ls -l
total 1
drwxr-xr-x  2 root  wheel  6 Mar 21 00:13 include
drwxr-xr-x  3 root  wheel  3 Mar 21 00:13 tool
In the /usr/local/go120/pkg directory there are two folders, namely include and tools. To make it clearer, how to implement PATH GO, we will install the "Google Indexing API" application, we will clone it from the Github server.

/var
root@ns3:~ # cd /var
root@ns3:/var # git clone https://github.com/unixwinbsd/FreeBSD_Google_Indexing_API.git
Once you have finished cloning, continue by installing the application.

/var/FreeBSD_Google_Indexing_API
root@ns3:/var # cd FreeBSD_Google_Indexing_API
root@ns3:/var/FreeBSD_Google_Indexing_API # go build -v ./...

Now you look again at the /usr/local/go120/pkg directory, run the ls -l command.

/var/FreeBSD_Google_Indexing_API
root@ns3:/var/FreeBSD_Google_Indexing_API # cd /usr/local/go120/pkg
root@ns3:/usr/local/go120/pkg # ls -l
total 2
drwxr-xr-x  2 root  wheel  6 Mar 21 00:13 include
drwxr-xr-x  3 root  wheel  3 Mar 21 00:33 pkg
drwxr-xr-x  3 root  wheel  3 Mar 21 00:13 tool
From the script above, we can see that there is a new folder called "pkg". Let's look at the contents of the pkg folder.

/var/FreeBSD_Google_Indexing_API
root@ns3:/usr/local/go120/pkg # cd pkg
root@ns3:/usr/local/go120/pkg/pkg # ls
mod
root@ns3:/usr/local/go120/pkg/pkg # cd mod
root@ns3:/usr/local/go120/pkg/pkg/mod # ls
cache                           go.opencensus.io@v0.24.0        google.golang.org
cloud.google.com                go.opentelemetry.io
github.com                      golang.org
With the example above, it is quite clear that all installation files will be stored in the /usr/local/go120/pkg directory. At this point, you have begun to understand the benefits of Path environments variable.


3. Composer Path Environment Variable

For any operating system that uses multiple users, running applications at root level is not recommended. Apart from security factors, it will also make it difficult to work with many users. Placement of files or libraries resulting from application installation should not be done in root. For example, in a composer application, if you do not set a path, all files will be placed in /root/.composer/cache.

In this section we will move the default composer path to the /usr/local directory, as we did in Java and Go. To set Path Composer, the method is almost the same as Java and Go. Your first step is to create the /usr/local/.composer/cache directory.

/usr/local/.composer/cache
root@ns3:~ # mkdir -p /usr/local/.composer/cache
root@ns3:~ # cd /usr/local/.composer/cache
root@ns3:/usr/local/.composer/cache #
After that, you open the csh.cshrc file, then type the script below.

/etc/csh.cshrc
root@ns3:~ # ee /etc/csh.cshrc
setenv COMPOSER_VERSION "2.7+"
setenv COMPOSER_HOME /usr/local/.composer/cache
setenv COMPOSER_MIRROR_PATH_REPOS /usr/local/.composer
setenv COMPOSER_BINARY /usr/local/.composer
In this article we use Composer version 2.7.0. After you determine the location of the Path Composer. Make this path permanent, so that all files resulting from the PHP Composer installation are placed on the path you specified above. Open .cshrc file, type below script in .cshrc file.

~/.cshrc
root@ns3:~ # ee .cshrc
set path = ($COMPOSER_HOME/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
set path = ($COMPOSER_MIRROR_PATH_REPOS/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
set path = ($COMPOSER_BINARY/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
So that all the Path changes above can be used immediately, reboot your computer.

Reboot
root@ns3:~ # reboot
Once you have read this article and applied it to your FreeBSD server, your knowledge of how to set or export environment variables in the csh/tcsh Shell Prompt from the command line on a FreeBSD system, will be of great help to find the location of each application's installation files. Everything looks neat, because you have arranged the files and directories in their respective places.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post