Setting Up Environment for Shell Scripting (vim, nano, gedit) - Part 3 of 34





Shell scripting environment setup is the first step every Linux user must complete before writing their first bash script. Prior to creating your first shell script, there are several tools that must be installed or configured correctly. The purpose of this tutorial is to outline how to configure the total shell scripting environment on a linux operating system by utilizing three of the most commonly used editors; vim, nano, gedit.

Why This Matters:

Many beginners jump straight into writing scripts without setting up a proper environment. This leads to common frustrations:

  • Scripts not running because the editor added invisible characters
  • No syntax highlighting, so errors are hard to spot
  • Wrong file permissions after saving

Setting up the right editor from day one saves hours of debugging later.

You may be completely new to the terminal. If so we recommend that you become familiarized with some simple commands prior to beginning the configuration of your shell scripting environment. Please review our linux terminal basics for new users (Linux Commands) page before proceeding with your scripting environment.

#01

Shell Scripting Environment Setup: What You Need Before You Begin

To write and run shell scripts on Linux, you need three things in place: a working Linux terminal, a text editor, and the Bash shell.
Most Linux distributions already include all three by default.
You can confirm that Bash is available on your system by checking its version.

bash
LinuxTeck.com
bash --version
OUTPUT
GNU bash, version 5.3.0(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.

You also need to know where your scripts will live. A common practice is to create a dedicated folder for your scripts inside your home directory.
If you are not yet comfortable navigating folders in the terminal, our cd command tips guide will help you get around quickly.

bash
LinuxTeck.com
mkdir ~/scripts
cd ~/scripts

Note:

The ~/scripts folder is just a naming convention. You can name it anything you like, such as ~/myshells or ~/bin.
The ~/bin folder is special because Linux automatically adds it to your PATH if it exists.
Learn more about how PATH works in our Bash PATH explained article.

#02

Installing vim on Linux

vim is one of the most powerful text editors for shell scripting available on Linux.
It is available on almost every Linux system and is the preferred editor for many experienced developers and sysadmins.
If it is not already installed, use the command below for your distribution.

bash
LinuxTeck.com
# Ubuntu / Debian
sudo apt install vim -y

# RHEL / Rocky / Fedora
sudo dnf install vim -y

Editor Comparison:

If you are on a RHEL or Fedora system and are not familiar with the dnf package manager, our DNF guide for beginners covers everything you need to know before installing packages.

Once installed, confirm it is available:

bash
LinuxTeck.com
vim --version | head -1
OUTPUT
VIM - Vi IMproved 9.2 (2026 Feb 14, compiled Apr 01 2026 10:22:31)

To create a new script using vim:

bash
LinuxTeck.com
vim hello.sh

Quick vim Tip:

When vim opens, press i to enter Insert mode and start typing.

When done, press Esc, then type :wq and hit Enter to save and exit.

vim also supports syntax highlighting for shell scripts by default.
For a full list of vim commands and shortcuts, see our vi/vim editor commands guide.

Common Mistake:

Beginners often get stuck in vim because they do not know how to exit. Pressing Ctrl+C does not exit vim.

Fix: Press Esc first, then type :q! to quit without saving, or :wq to save and quit.

#03

Installing nano on Linux

nano is the simplest editor for beginner shell scripting setup.
It shows keyboard shortcuts at the bottom of the screen, so you never have to memorize commands.
nano is usually pre-installed on most Ubuntu and Debian systems.

bash
LinuxTeck.com
# Ubuntu / Debian
sudo apt install nano -y

# RHEL / Rocky / Fedora
sudo dnf install nano -y

To open or create a script with nano:

bash
LinuxTeck.com
nano hello.sh

Tip:

In nano, press Ctrl+O to save and Ctrl+X to exit. These shortcuts are always visible at the bottom of the editor window, making nano the most beginner-friendly choice.

For a handy reference of all editor shortcuts, see our Linux text editors cheat sheet.

#04

Installing gedit on Linux (GUI Editor)

gedit is a graphical text editor that works well for users who prefer a visual interface over the command line.
It supports syntax highlighting for shell scripts and is part of the GNOME desktop environment.
If you are on a desktop Linux system, gedit is a great option for bash scripting environment setup.

bash
LinuxTeck.com
# Ubuntu / Debian
sudo apt install gedit -y

# RHEL / Rocky / Fedora
sudo dnf install gedit -y

To open a script file with gedit from the terminal:

bash
LinuxTeck.com
gedit hello.sh &

Note:

The & at the end runs gedit in the background so your terminal stays free to use. Without it, the terminal will be locked until you close gedit.
gedit requires a graphical desktop (X11 or Wayland). It will not work on headless servers. Use vim or nano for remote or server environments.
If you want to understand the difference between X11 and Wayland, check out our X11 vs Wayland article.

#05

Writing Your First Script and Setting Permissions

Once your editor is installed, you are ready to write a shell script.
Every shell script must start with a shebang line that tells the system which interpreter to use.
Here is a simple example using any of the three editors.

bash
LinuxTeck.com
#!/bin/bash
echo "Hello from LinuxTeck!"

After saving the file, you need to make it executable before running it.
Use the chmod command to give the script execute permission.
The echo command used in the script above is one of the most used commands in scripting — our echo command guide covers all its practical uses.

bash
LinuxTeck.com
chmod +x hello.sh
./hello.sh
OUTPUT
Hello from LinuxTeck!

Common Mistake:

Forgetting to add execute permission is the most common reason a script does not run. You will see a "Permission denied" error.

Fix: chmod +x yourscript.sh — See our full chmod command guide for more details on Linux file permissions.

#06

Choosing the right editor is a key part of your shell scripting environment setup.

Each editor has its own strengths. The right choice depends on your experience level, your working environment, and how you prefer to interact with the system.
Here is a quick comparison to help you decide.

Editor Comparison:

vim is best for experienced users and remote server work. It has the most features but the steepest learning curve.

nano is best for beginners and quick edits. It is straightforward, with all shortcuts visible on screen.

gedit is best for desktop users who prefer a graphical interface with mouse support and visual syntax highlighting.

For server-side scripting where no GUI is available, either vim or nano is the practical choice.
If you are working on a desktop machine and are new to Linux, starting with nano or gedit makes it easier to focus on learning scripting without fighting the editor itself.

Tip:

A good habit is to practice using vim at least for basic edits, since it is available on virtually every Linux system including minimal server installs where nano and gedit may not be present.
Once you are comfortable with your editor, the next step is putting your scripts to real use — our Linux bash scripting automation guide shows practical examples to get started.

You can also check which editors are currently installed on your system with a single command:

bash
LinuxTeck.com
which vim nano gedit
OUTPUT
/usr/bin/vim
/usr/bin/nano
/usr/bin/gedit

FAQ

Interview Questions (Practical)

What is the best editor for shell scripting on Linux?

A proper shell scripting environment setup always starts with picking the right editor for your workflow.
For beginners using a desktop, gedit or nano are easier to start with.
For anyone working on a remote server or wanting to build long-term skills, vim is the recommended choice because it is available everywhere and has powerful scripting support.
nano is a solid middle ground for quick edits without a learning curve.
For a complete list of vim commands, see our vi/vim editor commands guide.

What is the shebang line and why is it needed in every shell script?

The shebang line is the first line of a shell script and looks like #!/bin/bash.
It tells the Linux kernel which interpreter should be used to run the rest of the script.
Without it, the system may use the wrong shell or default to sh, which can cause scripts to behave differently than expected.

Why does my script say "Permission denied" even though it exists?

This happens because the script file does not have execute permission set.
Use the following command to fix it:

bash
LinuxTeck.com
chmod +x yourscript.sh

After running this, execute the script with ./yourscript.sh.

Can I use gedit on a Linux server without a desktop environment?

No. gedit is a graphical editor and requires a desktop environment (X11 or Wayland) to run.
On headless or minimal Linux servers, use vim or nano instead.
Both work entirely in the terminal with no GUI required.

How do I verify that vim or nano is already installed on my system?

Run the which command to check if the editor is available in your PATH:

bash
LinuxTeck.com
which vim
which nano

If a path like /usr/bin/vim is returned, the editor is installed. If no output appears, it is not installed and you can add it using your package manager.

Where should I store my shell scripts on Linux?

The most common location for personal scripts is ~/scripts or ~/bin.
Using ~/bin is convenient because Linux automatically adds it to your PATH if it exists, allowing you to run scripts by name without typing the full path.
Learn how PATH works in our Bash PATH explained article.

END

Summary

A proper shell scripting environment setup starts with choosing the right editor: vim for power users, nano for beginners, and gedit for those who prefer a graphical interface.
Once your editor is installed and your scripts folder is ready, the next step is learning to write scripts that actually do something useful.

If you want to test your knowledge, our Linux shell scripting interview questions is a great place to check how much you have learned so far.

🔗 Related Articles


LinuxTeck — A Complete Linux Learning Blog
Learn step-by-step how to automate Linux tasks with real-world scripts and practical examples.

About Sharon J

Sharon J is a Linux System Administrator with strong expertise in server and system management. She turns real-world experience into practical Linux guides on Linux Teck.

View all posts by Sharon J →

Leave a Reply

Your email address will not be published.

L