What is an IBM i PATH?
In PASE (Portable Application Solutions Environment), $PATH is an environment variable that stores a list of directories where the system searches for executable files, such as commands and programs. The PATH is like a *LIBL for open source. Just like library lists, the PATH setting only exists during our current connected session.
Set the VSCODE/IBMi PATH to Open Source Packages on IBM i
Setting the VSCODE IBM i PATH to open source packages on IBM i is beneficial for several reasons:
- Ease of Access: By updating the default PATH to include
/QOpenSys/pkgs/bin
, you can easily access open source tools and packages without needing to specify their full paths each time. This is similar to how library lists work on IBM i - Efficiency: It streamlines your workflow by allowing you to run commands and scripts directly from the terminal or within VS Code, improving productivity and reducing the chance of errors
- Integration: It enhances the integration of open source tools with your development environment, making it easier to use languages and tools like Python, Node.js, and others directly on IBM i
- Consistency: Ensuring that the PATH is set correctly helps maintain consistency across different development environments and team members, making collaboration smoother
My default path looks like this:
/QOpenSys/usr/bin:/usr/ccs/bin:/QOpenSys/usr/bin/X11:/usr/sbin:.:/usr/bin
We want to add the path to the opensource package binaries (/QOpenSys/pkgs/bin
) and the NodeJS20 (/QOpenSys/pkgs/lib/nodejs20/bin). Setting the IBM i open-source environment path is easy from within VS-Code. This helps resolve program names to their absolute (IFS) paths at connection time (similar to setting a *LIBL during signon).
NOTE: if you have a different version of NodeJS installed changed the number in the path to match your version.
We are going to add these 2 lines to our VS-CODE startup routine when connecting to our IBM i System
# Suffix Main Binaries & NodeJS to existing PATH
PATH=$PATH:/QOpenSys/pkgs/bin:/QOpenSys/pkgs/lib/nodejs20/bin
export PATH PASE_PATH
The command PATH=$PATH:
is used to add the new path elements after the existing /something
PATH
environment variable in a Unix-like operating system, including IBM i’s PASE (Portable Application Solutions Environment).
Here’s what it does:
PATH
: This is an environment variable that specifies a list of directories where the system looks for executable files. When you type a command in the terminal, the system searches these directories to find the executable./QOpenSys/pkgs/bin
: This is the directory where open source packages are typically installed on IBM i. By adding this directory to thePATH
, you make it easier to access these tools without needing to specify their full paths. I am also adding my version of NodeJS /QOpenSys/pkgs/lib/nodejs20/bin$PATH
: This represents the current value of thePATH
variable. By including it, you ensure that the existing directories inPATH
are preserved and the new directory is added to the beginning.
The command export PATH PASE_PATH
is used to modify the PATH
environment variable in a Unix-like operating system, including IBM i’s PASE (Portable Application Solutions Environment).
NOTE: PASE (Portable Application Solutions Environment) for IBM i is case-sensitive. It distinguishes between uppercase and lowercase letters in file names and commands – so be careful!
Where do we define this PATH change?
.profile
, .bash_profile
and .bashrc
are all configuration files used by the Bash shell, but they serve slightly different purposes and are executed at different times.
- Put in .bash_profile for CLI usage
- Put in .profile for CLI usage (not specific to Bash)
- Put in .bashrc for Code for IBM i usage
.bash_profile
:
- This file is executed when the Bash shell is started as a login shell, typically when you log in to a system or start a new terminal session.
- It is usually used to set environment variables, such as
PATH
,USER
, andHOME
, that are available to all shells and programs. - Commands in this file are executed only once, at login time.
.profile
:
- This file is also executed when the Bash shell is started as a login shell, but it is not specific to Bash.
- It is used by other shells, such as the Bourne shell and the Korn shell, as well as by Bash.
- Like
.bash_profile
, it is used to set environment variables and is executed only once, at login time.
.bashrc
:
- This file is executed every time a new Bash shell is started, whether it’s a login shell or not.
- It is used to set shell-specific settings, such as aliases, functions, and shell options.
- Commands in this file are executed every time a new shell is started, which can be useful for setting up the shell environment.
Here’s a general rule of thumb:
- Use
.bash_profile
or.profile
for setting environment variables that should be available to all shells and programs. - Use
.bashrc
for setting shell-specific settings, such as aliases and functions, that should be executed every time a new shell is started.
Note that if .bash_profile
exists, Bash will not read .profile
. If you want to use .profile
, you should not have a .bash_profile
file.
What do we set for VS Code for IBM i?
Since Code for IBM i uses bash as its communication system between your local machine and the IBM i PASE environment, for compiles) so we just need the
and .bash_profile
.bashrc
We simply need to create file called
within our home directory for the user we are using to connect to our system. This should be the IFS location .bash_profile
/home/USERNAME/.bash_profile
You can see this on your user profile. In my case doing a DSPUSRPRF NICKLITTEN and paging down a few times until you see:
We can easily create this file using the IFS EXPLORER within VS CODE. Just right click the /home/username folder and create file .bash_profile
.bashrc
& .bash
_profile should both contain:
PATH=$PATH:/QOpenSys/pkgs/bin:/QOpenSys/pkgs/lib/nodejs20/bin
export PATH PASE_PATH
That’s it!
Once you have created you just need to disconnect and reconnect to make it happen. Now, every time you launch the SHELL for commands, it will automagically add the path to all the opensource packages installed on your IBM i Power System.
You can check the value of the PASE PATH variable (remember it is case sensitive):
echo $PATH
Enjoy 🙂