Linux run console application

How to Run a Program from the Command Line on Linux

This article was co-authored by wikiHow staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for wikiHow. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College.

The wikiHow Tech Team also followed the article’s instructions and verified that they work.

This article has been viewed 279,480 times.

Most Linux distributions have a graphical user interface that allows you to open programs by just clicking on the program’s icon in the Apps menu. However, there are situations where you may want to run a program from the Terminal. The Terminal is a powerful tool that allows you to run programs and manage your Linux system using keyboard commands. This wikiHow teaches you how to run a program from the Terminal in Linux.

Running a Program From the Terminal

Image titled Run a Program from the Command Line on Linux Step 1

Press Ctrl + Alt + T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor.

Image titled Run a Program from the Command Line on Linux Step 2

  • For example, if you want to run Firefox from the Terminal, you would simply type firefox and press Enter.
  • Type -h or —help after the program name to display the help menu for that program. Many programs have additional command modifiers you can use to launch the program in a specific way. For example, you can launch a website in a web browser by typing the web browser name followed by the web address and press Enter to launch that website in the web browser (i.e. firefox www.wikihow.com .
  • If you receive a message that says you don’t have permission to run a program or access is denied, type sudo before the program name and press Enter. The «sudo» command allows regular users to run Terminal commands with administrative privileges or root access.
  • If you want to run a C or C++ program from the Terminal, you will first need to complie the program before you can launch it from the Terminal.

Running a Program Outside the $PATH Variable

Image titled Run a Program from the Command Line on Linux Step 3

Press Ctrl + Alt + T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor.

Image titled Run a Program from the Command Line on Linux Step 4

Type cd followed by a space and the location the program file is saved to. If the program launch file is saved to a location that is not in your $PATH variable, then you will need to navigate to that location inside the Terminal. You can do so using the «cd» command. For example, if you have folder for Python programs saved in your «Documents» folder, you can navigate to it in the Terminal by typing cd ~/Documents/Python or something similar, and then press Enter.

Читайте также:  Modbus tcp master linux

Image titled Run a Program from the Command Line on Linux Step 5

Type chmod a+x [filename] and press ↵ Enter . Replace «filename» with the actual launch file of the program. The «chmod a+x» command tells Linux the file is an executable file. [1] X Research source

Image titled Run a Program from the Command Line on Linux Step 6

Type «./» followed by the launch filename and press ↵ Enter . This launches the program. For example, if you have a Python file called «Helloworld.py», you would type ./helloworld.py to launch the file. [2] X Research source

Adding a Directory to your $PATH Variable

Image titled Run a Program from the Command Line on Linux Step 7

Press Ctrl + Alt + T to open the Terminal. If you cannot run a program by simply typing the program’s name, you may need to add the directory that the program is installed in to your $PATH variable. You can do this from the Terminal as well. Use the keyboard shortcut to open the Terminal if you haven’t already done so.

Image titled Run a Program from the Command Line on Linux Step 8

  • For example, if you have a program installed in the «bin» directory of your «Home» folder, you would type export PATH=$PATH:$Home/bin and press Enter. This will temporarily add the «$Home/bin» directory to your $PATH variable.
  • You can see which directories are currently added to your $PATH variable by typing the command echo $PATH and pressing Enter.

Image titled Run a Program from the Command Line on Linux Step 9

Type nano ~/.bashrc and press ↵ Enter . This opens the «.bashrc» file in a text editor that is based in the Terminal. You can use this file to permanently add the directory to your $PATH variable.

Image titled Run a Program from the Command Line on Linux Step 10

Add the «export PATH» command to the file. To do so, scroll down to the bottom of the file using the mouse wheel and type export PATH=$PATH:[path/to/program] at the bottom. Replace «[path/to/program]» with the actual directory tree the program is installed in. [3] X Research source

Image titled Run a Program from the Command Line on Linux Step 11

Image titled Run a Program from the Command Line on Linux Step 12

Press Y and press ↵ Enter . This confirms that you want to save and exit the text editor. You will be returned to the standard command prompt in the Terminal.

Image titled Run a Program from the Command Line on Linux Step 13

Type source ~/.bashrc and press ↵ Enter . This loads the updated $PATH variable into your current session. [4] X Research source

Image titled Run a Program from the Command Line on Linux Step 14

Type the name of the program and press ↵ Enter . With the program’s directory now added to your $PATH variable, you should be able to launch the program by simply typing the program name and pressing Enter.

Installing and Uninstalling a Program in the Terminal

Image titled Run a Program from the Command Line on Linux Step 15

Press Ctrl + Alt + T to open the Terminal. In addition to launching programs from within the Terminal, you can also install and uninstall programs from within the Terminal. Use the keyboard shortcut to open the Terminal if you haven’t already done so.

Image titled Run a Program from the Command Line on Linux Step 16

Type sudo apt install [app_name] and press ↵ Enter (Debian). Replace «[app_name]» with the actual name of the program you want to install. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint.

Image titled Run a Program from the Command Line on Linux Step 17

Type sudo apt remove [app_name] and press ↵ Enter (Debian). Replace «[app_name]» with the name of the app you want to uninstall. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint.

Читайте также:  Подключить ftp как диск linux

Image titled Run a Program from the Command Line on Linux Step 18

Type sudo dnf install [app_name] and press ↵ Enter (Red Hat). Replace «[app_name]» with the actual name of the program you want to install. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS.

Image titled Run a Program from the Command Line on Linux Step 19

Type sudo dnf remove [app_name] and press ↵ Enter (Red Hat). Replace «[app_name]» with the name of the app you want to uninstall. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS. [5] X Research source

Image titled Run a Program from the Command Line on Linux Step 20

Type the name of the program and press ↵ Enter . Once the program is installed, you can launch the program by simply typing the program’s name and pressing Enter in the Terminal.

Expert Q&A

Tips

You Might Also Like

Convert from Binary to Decimal

Format Text as Code in Discord

Change Code on Schlage Lock

How to Change 4-Digit User Codes on Schlage Locks

Delay a Batch File

How to Delay a Batch File: Timeout, Pause, Ping, Choice & Sleep

Reset Schlage Keypad Lock Without Programming Code

How to Factory Reset a Schlage Lock & Restore the Default Programming Code

Write Pseudocode

Learn to Write Pseudocode: What It Is and Why You Need It

Download a File from GitHub

Code

Make an Exe File

View Source Code

Start Learning Computer Programming

How to Start Coding: The Beginner’s Guide to Programming

Make a Program Using Notepad

Download a GitHub Folder

3 Ways to Download GitHub Directories and Repositories

Источник

C# — How to create, build and run a «hello world» console app on Linux

This post describes how to create a simple Console application and run it on Linux, for this we will be using WSL (Windows Subsystem for Linux) running Ubuntu 22.

Installing dotnet

We start by installing dotnet:

sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-6.0 

For Ubuntu 22 you can install dotnet 6 with the above two commands, if you are on a different distro, follow this guide from Microsoft.

Creating a console app

Next up we will create a simple console application that writes «Hello World» to the console. Luckily this is the default implementation when you create a new console application in .Net:

cd /home/peterdrasmussen/ mkdir test dotnet new console 

If we use ls we see the following files:

If we cat the Program.cs file we see the following:

//See https://aka.ms/new-console-template for more information Console.WriteLine("Hello, World!"); 

Which is simply an application that logs «Hello World» to the console, exactly what we need! Next up we will build and run this.

Building and running the application

In order to build the application we need to run dotnet build and if we use the ls command afterwards, we will see that there is now a bin folder:

Program.cs bin obj test.csproj 

We have successfully built our application and we can now run it using the dotnet command on the dll in the bin folder:

cd bin/Debug/net6.0/ ls ref test test.deps.json test.dll test.pdb test.runtimeconfig.json dotnet test.dll Hello, World! 

In the above we go to the directory where the output from the build is ( bin/Debug/net6.0/ ) and use ls once again to see the contents. We then start the application using the dotnet command and it outputs the string «Hello, World!» to the console, that completes the goal of this blog post!

That is all

I hope you enjoyed this short post on how to write a simple «Hello world» .Net application on Linux, I wanted to write a simple and straightforward guide from start to finish. As always: feel free to leave a comment down below!

Читайте также:  Настройка мандатной в линукс

Peter Daugaard Rasmussen

Programmer, Developer, Consultant.

Источник

How to create executable console app from .NET Core 2.0 in Linux?

In order to create a standalone console app in Linux, you should use a self-contained deployment (SCD) publishing mode for your dotnet core app:

This will generate a single binary that bundles the target framework and can be executed independently without any extra shell-scripts or pre-installed dotnet runtime.

I recommend to use the official dotnet cli console template and then publish your project as a —self-contained switch by specifying your target runtime (eg: linux-x64 ) and framework what you use.

So start with the basic console template:

dotnet new console -o myconsoleapp cd myconsoleapp 

Edit program.cs to process your input-file or other arguments based on your business logic, eg: nano program.cs and add something like:

using System; namespace myconsoleapp < class Program < static void Main(string[] args) < Console.WriteLine("Hello Linux!"); if (args.Length >0) < Console.WriteLine("Input is: " + args[0]); >> > > 

Test your application with dotnet run file_inputs.txt and it should print to the console correctly.

In order to get the binaries and the bundled framework to be distributed, you should run dotnet publish :

dotnet publish -c release --self-contained --runtime linux-x64 --framework netcoreapp2.0 

You can then distribute your publish folder and then execute your app just simply by:

./myconsoleapp file_inputs.txt 

Here’s a bit more detailed article about creating standalone Linux console app in dotnet core:

Also can read more here about other available Linux templates at the publish page:

Источник

How to run a .NET Core console application on Linux

Running a .NET Core console application on Linux is similar to running it on Windows. Here are the general steps to follow:

  1. Build the application: Build the .NET Core console application using the dotnet build command in the terminal or command line.
  2. Publish the application: Publish the .NET Core console application using the dotnet publish command. This command will generate the necessary files to run the application on Linux.
  3. Transfer the files to Linux: Transfer the published files to the Linux machine. You can use a file transfer protocol such as FTP or SCP to transfer the files.
  4. Set file permissions: Set the necessary file permissions on the published files. You can use the chmod command to set the necessary file permissions.
  5. Run the application: Run the .NET Core console application on Linux using the dotnet command in the terminal or command line. For example, if your console application is named myapp.dll , you would run the application using the following command:

These are the general steps to run a .NET Core console application on Linux. However, the specific steps may vary depending on the version of .NET Core you are using, the Linux distribution you are running, and other factors.

More C# Questions

Professional provider of PDF & Microsoft Word and Excel document editing and modifying solutions, available for ASP.NET AJAX, Silverlight, Windows Forms as well as WPF. We are dedicated to provide powerful & profession PDF/Word/Excel controls.

Product

Hot How-to

Copyright © 2010 — . iDiTect All rights reserved.

Источник

Оцените статью
Adblock
detector